diff --git a/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/nullandempty/NullAndEmptyStringUnitTest.java b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/nullandempty/NullAndEmptyStringUnitTest.java new file mode 100644 index 0000000000..332a16fd84 --- /dev/null +++ b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/nullandempty/NullAndEmptyStringUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.nullandempty; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Test; + +public class NullAndEmptyStringUnitTest { + + @Test + void givenANullAndEmptyString_whenUsingStringMethods_thenShouldGetExpectedResult() { + String nullString = null; + String emptyString = ""; + assertTrue(emptyString.equals("")); + assertThrows(NullPointerException.class, () -> nullString.length()); + } + + @Test + void givenANullAndEmptyString_whenCheckingEquality_thenShouldGetExpectedResult() { + String nullString = null; + String emptyString = ""; + assertFalse(emptyString.equals(nullString)); + assertFalse(emptyString == nullString); + } + +}