BAEL-6342 JUnit Test Class for Null and Empty String (#13963)

This commit is contained in:
brokenhardisk 2023-05-11 05:53:11 +02:00 committed by GitHub
parent a74f4ec8f5
commit 4192bf3bdc
1 changed files with 27 additions and 0 deletions

View File

@ -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);
}
}