File tree Expand file tree Collapse file tree
main/java/com/baeldung/optional
test/java/com/baeldung/optional Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ## Core Java 11
2+
3+ This module contains articles about Java 11 core features
4+
5+ ### Relevant articles
6+ - [ Guide to Java 8 Optional] ( https://www.baeldung.com/java-optional )
7+
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project
3+ xmlns =" http://maven.apache.org/POM/4.0.0"
4+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
5+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
6+ <modelVersion >4.0.0</modelVersion >
7+ <artifactId >core-java-11-2</artifactId >
8+ <version >0.1.0-SNAPSHOT</version >
9+ <name >core-java-11-2</name >
10+ <packaging >jar</packaging >
11+
12+ <parent >
13+ <groupId >com.baeldung</groupId >
14+ <artifactId >parent-modules</artifactId >
15+ <version >1.0.0-SNAPSHOT</version >
16+ <relativePath >../..</relativePath >
17+ </parent >
18+
19+ <dependencies >
20+ <dependency >
21+ <groupId >org.assertj</groupId >
22+ <artifactId >assertj-core</artifactId >
23+ <version >${assertj.version} </version >
24+ <scope >test</scope >
25+ </dependency >
26+ </dependencies >
27+
28+ <build >
29+ <plugins >
30+ <plugin >
31+ <groupId >org.apache.maven.plugins</groupId >
32+ <artifactId >maven-compiler-plugin</artifactId >
33+ <version >${maven-compiler-plugin.version} </version >
34+ <configuration >
35+ <source >${maven.compiler.source.version} </source >
36+ <target >${maven.compiler.target.version} </target >
37+ </configuration >
38+ </plugin >
39+ </plugins >
40+ </build >
41+
42+ <properties >
43+ <maven .compiler.source.version>11</maven .compiler.source.version>
44+ <maven .compiler.target.version>11</maven .compiler.target.version>
45+ <assertj .version>3.17.2</assertj .version>
46+ </properties >
47+
48+ </project >
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 77import java .util .function .Supplier ;
88import java .util .stream .Stream ;
99
10- import static org .junit .Assert .*;
10+ import static org .junit .Assert .assertEquals ;
11+ import static org .junit .Assert .assertFalse ;
12+ import static org .junit .Assert .assertTrue ;
1113
1214public class OptionalChainingUnitTest {
1315
Original file line number Diff line number Diff line change 99import java .util .NoSuchElementException ;
1010import java .util .Optional ;
1111
12- import static org .junit .Assert .*;
12+ import static org .junit .Assert .assertEquals ;
13+ import static org .junit .Assert .assertFalse ;
14+ import static org .junit .Assert .assertTrue ;
1315
1416public class OptionalUnitTest {
1517
@@ -262,6 +264,12 @@ public void whenOrElseThrowWorks_thenCorrect() {
262264 .orElseThrow (IllegalArgumentException ::new );
263265 }
264266
267+ @ Test (expected = NoSuchElementException .class )
268+ public void whenNoArgOrElseThrowWorks_thenCorrect () {
269+ String nullName = null ;
270+ String name = Optional .ofNullable (nullName ).orElseThrow ();
271+ }
272+
265273 public String getMyDefault () {
266274 LOG .debug ("Getting default value..." );
267275 return "Default Value" ;
Original file line number Diff line number Diff line change 107107 <uberjar .name>benchmarks</uberjar .name>
108108 <jmh .version>1.22</jmh .version>
109109 <eclipse .collections.version>10.0.0</eclipse .collections.version>
110- <shade .plugin.version>10.0.0 </shade .plugin.version>
110+ <shade .plugin.version>3.2.4 </shade .plugin.version>
111111 </properties >
112112
113113</project >
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ This module contains articles about Java Optional.
44
55### Relevant Articles:
66- [ Java Optional as Return Type] ( https://www.baeldung.com/java-optional-return )
7- - [ Guide to Java 8 Optional] ( https://www.baeldung.com/java-optional )
87- [ Java Optional – orElse() vs orElseGet()] ( https://www.baeldung.com/java-optional-or-else-vs-or-else-get )
98- [ Transforming an Empty String into an Empty Optional] ( https://www.baeldung.com/java-empty-string-to-empty-optional )
109- [ Filtering a Stream of Optionals in Java] ( https://www.baeldung.com/java-filter-stream-of-optional )
You can’t perform that action at this time.
0 commit comments