forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eugenp#694 from anton-k11/master
BAEL-27 Java 9 New Features
- Loading branch information
Showing
4 changed files
with
49 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
3 changes: 1 addition & 2 deletions
3
core-java-9/src/test/java/com/baeldung/java9/MultiResultionImageTest.java
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
21 changes: 21 additions & 0 deletions
21
core-java-9/src/test/java/com/baeldung/java9/OptionalToStreamTest.java
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,21 @@ | ||
package com.baeldung.java9; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class OptionalToStreamTest { | ||
|
||
@Test | ||
public void testOptionalToStream() { | ||
Optional<String> op = Optional.ofNullable("String value"); | ||
Stream<String> strOptionalStream = op.stream(); | ||
Stream<String> filteredStream = strOptionalStream.filter((str) -> { | ||
return str != null && str.startsWith("String"); | ||
}); | ||
assertEquals(1, filteredStream.count()); | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core-java-9/src/test/java/com/baeldung/java9/SetExamplesTest.java
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,26 @@ | ||
package com.baeldung.java9; | ||
|
||
import java.util.Set; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SetExamplesTest { | ||
|
||
@Test | ||
public void testUnmutableSet() { | ||
Set<String> strKeySet = Set.of("key1", "key2", "key3"); | ||
try { | ||
strKeySet.add("newKey"); | ||
} catch (UnsupportedOperationException uoe) { | ||
} | ||
assertEquals(strKeySet.size(), 3); | ||
} | ||
|
||
@Test | ||
public void testArrayToSet() { | ||
Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; | ||
Set<Integer> intSet = Set.of(intArray); | ||
assertEquals(intSet.size(), intArray.length); | ||
} | ||
} |