-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and implement CompanyEmployee class
Removed OptionalExceptionDemo file and added new test cases for sorting a list and the CompanyEmployee class. Updated build.gradle to use the latest JUnit version. Additionally, fixed a minor issue in FlatMapDemo related to checking for empty orders.
- Loading branch information
Showing
6 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package interfaces; | ||
|
||
public class CompanyEmployee implements Company, Employee { | ||
private final String first; | ||
private final String last; | ||
|
||
public CompanyEmployee(String first, String last) { | ||
this.first = first; | ||
this.last = last; | ||
} | ||
|
||
public String getName() { | ||
return "%s works for %s".formatted(Employee.super.getName(), Company.super.getName()); | ||
} | ||
|
||
@Override | ||
public String getFirst() { | ||
return first; | ||
} | ||
|
||
@Override | ||
public String getLast() { | ||
return last; | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Converting caffeine into code for $$$"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package streams; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class SortListTest { | ||
private final List<String> list = | ||
List.of("banana", "apple", "orange", "kiwi", "grape"); | ||
|
||
@Test | ||
void sortList_collections() { | ||
// throws UnsupportedOperationException because | ||
// List.of() returns an unmodifiable list | ||
// Collections.sort(list); | ||
// System.out.println(list); | ||
List<String> sorted = list.stream() | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
System.out.println(sorted); | ||
System.out.println(list); | ||
} | ||
} |