Skip to content

Commit 5aed1b8

Browse files
alimateKevinGilmore
authored andcommitted
Added a test for Optional#isEmpty. (eugenp#5938)
1 parent 292c80c commit 5aed1b8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.optional;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Optional;
6+
7+
import static org.junit.Assert.assertFalse;
8+
import static org.junit.Assert.assertTrue;
9+
10+
/**
11+
* Unit tests for {@link Optional} in Java 11.
12+
*/
13+
public class OptionalUnitTest {
14+
15+
@Test
16+
public void givenAnEmptyOptional_isEmpty_thenBehavesAsExpected() {
17+
Optional<String> opt = Optional.of("Baeldung");
18+
assertFalse(opt.isEmpty());
19+
20+
opt = Optional.ofNullable(null);
21+
assertTrue(opt.isEmpty());
22+
}
23+
}

0 commit comments

Comments
 (0)