From 6a09ba47e8581972a7e81eb45e4239c9b5c6b037 Mon Sep 17 00:00:00 2001
From: Saikat <41847480+psychsane@users.noreply.github.com>
Date: Wed, 19 Sep 2018 22:26:11 +0530
Subject: [PATCH] Check String is not empty
Issue: BAEL-2128
---
java-strings/pom.xml | 6 +++
.../baeldung/string/StringEmptyUnitTest.java | 51 +++++++++++++++++++
2 files changed, 57 insertions(+)
create mode 100644 java-strings/src/test/java/com/baeldung/string/StringEmptyUnitTest.java
diff --git a/java-strings/pom.xml b/java-strings/pom.xml
index 2afe18f07a..29e992a2ce 100644
--- a/java-strings/pom.xml
+++ b/java-strings/pom.xml
@@ -52,6 +52,11 @@
icu4j
${icu4j.version}
+
+ com.google.guava
+ guava
+ ${guava.version}
+
com.vdurmont
@@ -92,6 +97,7 @@
3.6.1
1.19
61.1
+ 26.0-jre
\ No newline at end of file
diff --git a/java-strings/src/test/java/com/baeldung/string/StringEmptyUnitTest.java b/java-strings/src/test/java/com/baeldung/string/StringEmptyUnitTest.java
new file mode 100644
index 0000000000..17b13f89de
--- /dev/null
+++ b/java-strings/src/test/java/com/baeldung/string/StringEmptyUnitTest.java
@@ -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));
+ }
+
+}