parent
4d2780379d
commit
6a09ba47e8
|
@ -52,6 +52,11 @@
|
|||
<artifactId>icu4j</artifactId>
|
||||
<version>${icu4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.vdurmont</groupId>
|
||||
|
@ -92,6 +97,7 @@
|
|||
<assertj.version>3.6.1</assertj.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<icu4j.version>61.1</icu4j.version>
|
||||
<guava.version>26.0-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.string;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString;
|
||||
import static org.hamcrest.text.IsEmptyString.isEmptyString;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
public class StringEmptyUnitTest {
|
||||
|
||||
private String text = "baeldung";
|
||||
|
||||
@Test
|
||||
public void givenAString_whenCheckedForEmptyUsingJunit_shouldAssertSuccessfully() {
|
||||
assertTrue(!text.isEmpty());
|
||||
assertFalse(text.isEmpty());
|
||||
assertNotEquals("", text);
|
||||
assertNotSame("", text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenCheckedForEmptyUsingHamcrest_shouldAssertSuccessfully() {
|
||||
assertThat(text, not(isEmptyString()));
|
||||
assertThat(text, not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenCheckedForEmptyUsingCommonsLang_shouldAssertSuccessfully() {
|
||||
assertTrue(StringUtils.isNotBlank(text));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenCheckedForEmptyUsingAssertJ_shouldAssertSuccessfully() {
|
||||
Assertions.assertThat(text).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenCheckedForEmptyUsingGuava_shouldAssertSuccessfully() {
|
||||
assertFalse(Strings.isNullOrEmpty(text));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue