Added a test for Optional#isEmpty. (#5938)
This commit is contained in:
parent
292c80cf85
commit
5aed1b89bb
@ -0,0 +1,23 @@
|
||||
package com.baeldung.optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Optional} in Java 11.
|
||||
*/
|
||||
public class OptionalUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAnEmptyOptional_isEmpty_thenBehavesAsExpected() {
|
||||
Optional<String> opt = Optional.of("Baeldung");
|
||||
assertFalse(opt.isEmpty());
|
||||
|
||||
opt = Optional.ofNullable(null);
|
||||
assertTrue(opt.isEmpty());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user