Curso Básico de Testing en Java

Curso Básico de Testing en Java

Ferran Maylinch Carrasco

Ferran Maylinch Carrasco

Reto 1: crear la función isEmpty

11/24

Lectura

En una aplicación que estamos construyendo, nos hemos dado cuenta de que comprobamos muchas veces si un string está vacío o no. Por ello, vamos a implementar una función que realice esta tarea.

...

Regístrate o inicia sesión para leer el resto del contenido.

Aportes 281

Preguntas 3

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

Les dejo mi aporte con JUnit5

Método:

    public static boolean isEmpty(String string) {
        return string == null || string.trim().length() == 0;
    }

Tests:

class StringUtilsTest {

    @Nested
    @DisplayName("isEmpty method")
    class IsEmpty {

        @Test
        @DisplayName("when string is null")
        void trueWhenNull() {
            assertTrue(StringUtils.isEmpty(null));
        }

        @Test
        @DisplayName("when string just has spaces")
        void trueWhenEmptySpace() {
            assertTrue(StringUtils.isEmpty("  "));
        }

        @Test
        @DisplayName("when string is empty")
        void trueWhenEmpty() {
            assertTrue(StringUtils.isEmpty(""));
        }

        @Test
        @DisplayName("when has chars")
        void falseWhenHasChars() {
            assertFalse(StringUtils.isEmpty("hello"));
        }

    }
}

StringUtil.java

public static boolean isEmpty(final String str) {
	return str == null || str.trim().isEmpty();
}

StringUtilTest.java

	@Test
	public void string_is_not_empty() {
		assertFalse(StringUtil.isEmpty("hola"));
	}
	
	@Test
	public void string_is_empty() {
		assertTrue(StringUtil.isEmpty(""));
	}
	
	@Test
	public void string_null_is_empty() {
		assertTrue(StringUtil.isEmpty(null));
	}

Excelente reto para empezar en el mundo de pruebas unitarias. Consideren crear un nuevo curso con Junit 5. Saludos

// Class
public class StringUtil {

	public static boolean isEmpty(String str) {
		return str == null || str.trim().equals("");
	}
}

// Test class
public class StringUtilTest {
	@Test public void testNotEmptyString() {
		assertFalse(StringUtil.isEmpty("abcde"));
	}

	@Test public void testEmptyString() {
		assertTrue(StringUtil.isEmpty(""));
	}

	@Test public void testNullString() {
		assertTrue(StringUtil.isEmpty(null));
	}

	@Test public void testSpacesString() {
		assertTrue(StringUtil.isEmpty("    "));
	}
}

Esta es mi Solucion:

StringUtil.java

        if( str==null || str.isBlank()){
            return true;
        }
        return false;

StringUtilTest.java

public class StringUtilTest {
    @Test
    public void verifyStrNotEmpty() {
        Assert.assertFalse(StringUtil.isEmpty("Oscar"));
    }
    @Test
    public void verifyStrisEmpty() {
        Assert.assertTrue(StringUtil.isEmpty(""));
    }
    @Test
    public void verifyStrisNull() {
        Assert.assertTrue(StringUtil.isEmpty(null));
    }
    @Test
    public void verifyStrWithSpaces() {
        Assert.assertTrue(StringUtil.isEmpty("  "));
    }
}

En mi caso consideré también que “null” es vacío, esto porque en algunos lugares he visto que para realizar un cast a String suelen utilizar + “”.

public static boolean isEmpty(String str) {
     return str == null || str.trim().replace("null", "").isEmpty();
}

Aquí los test

    @Test
    public void string_is_null() {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_is_empty() {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_is_empty_with_spaces() {
        assertTrue(StringUtil.isEmpty("   "));
    }

    @Test
    public void string_is_not_empty() {
        assertFalse(StringUtil.isEmpty("   hola"));
    }

    @Test
    public void string_is_differente_from_null_text() {
        assertTrue(StringUtil.isEmpty("null"));
    }
public static boolean isEmpty(String str) {
 return str == null || str.trim().length() <= 0;			 }

@Test
public void string_quotation_marks_is_empty() {
	assertTrue(StringUtil.isEmpty(""));
}

@Test
public void string_space_is_empty() {
	assertTrue(StringUtil.isEmpty(" "));
}

@Test
public void string_null_is_empty() {
	assertTrue(StringUtil.isEmpty(null));
}
 public static boolean isEmpty(String str) {
	 return str == null || str.trim().length() <= 0;			
 }

@Test
public void string_is_not_empty() {
assertFalse(StringUtil.isEmpty(“hola”));
}

@Test
public void string_quotation_marks_is_empty() {
	assertTrue(StringUtil.isEmpty(""));
}

@Test
public void string_space_is_empty() {
	assertTrue(StringUtil.isEmpty(" "));
}

@Test
public void string_null_is_empty() {
	assertTrue(StringUtil.isEmpty(null));
}

StringUtil.java

public static boolean isEmpty(String string) {

        return string == null || string.equals("") || string.trim().length() == 0;
    }

StringUtilTest.java

@Test
    public void stringIsNotEmpty() {
        boolean response = StringUtil.isEmpty("abcd");
        Assert.assertFalse(response);
    }

    @Test
    public void stringIsEmpty() {
        boolean response = StringUtil.isEmpty("");
        Assert.assertTrue(response);
    }

    @Test
    public void stringIsNull() {
        boolean response = StringUtil.isEmpty(null);
        Assert.assertTrue(response);
    }

    @Test
    public void stringWithSpaces() {
        boolean response = StringUtil.isEmpty("      ");
        Assert.assertTrue(response);
    }

muy bien definidos los criterios de aceptación de la función, pero como sabriamos cuales son los criterios, porque puede que no se hayan contemplado algunas situaciones en alguna función que hayamos implementado.

public class StringUtil {

    public static boolean isEmpty(String str) {
         return str.trim().isEmpty() || str==null;
    }
}

package com.platzi.javatests.Empty;

import org.junit.Test;

import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

public class StringUtil {

public static boolean isEmpty(String str){
    return str == null || str.trim().length() <= 0;
}


@Test
public void string_is_not_empty(){
    String str = "Josef Ramos";
    StringUtil stringUtil = new StringUtil();

    assertFalse(stringUtil.isEmpty(str));
}

@Test
public void string_is_empty(){
    String str = "";
    StringUtil stringUtil = new StringUtil();

    assertTrue(stringUtil.isEmpty(str));
}

@Test
public void string_is_blanc(){
    String str = " ";
    StringUtil stringUtil = new StringUtil();

    assertTrue(stringUtil.isEmpty(str));
}

@Test
public void string_is_null(){
    String str = null;
    StringUtil stringUtil = new StringUtil();

    assertTrue(stringUtil.isEmpty(str));
}

}

public static boolean isEmpty(String str) {
        return str == null || str.trim().isEmpty();
    }

    @Test
    public void correcta() {
        //COMPROBACIÓN DE QUE EL DATO SEA EL ESPERADO
        assertFalse(StringUtil2.isEmpty("PALABRA"));
    }

    @Test
    public void isEmpty() {
        //COMPROBACIÓN DE QUE EL DATO SEA EL ESPERADO
        assertTrue(StringUtil2.isEmpty(""));
    }

    @Test
    public void isNull() {
        //COMPROBACIÓN DE QUE EL DATO SEA EL ESPERADO
        assertTrue(StringUtil2.isEmpty(null));
    }

    @Test
    public void con_espacios() {
        //COMPROBACIÓN DE QUE EL DATO SEA EL ESPERADO
        assertTrue(StringUtil2.isEmpty("   "));
    }
public class StringUtil {

    public static boolean isEmpty(String str){
        return str == null  || str.trim().equals("");
    }
}
public class StringUtilTest {

    StringUtil stringUtil;

    @Before
    public void setup(){
         stringUtil = new StringUtil();
    }


    @Test
    public void when_not_empty_string_it_will_return_false(){
        //arrange
        String anyNotEmptyString = "not_empty_string";
        //act
        boolean isEmptyString = stringUtil.isEmpty(anyNotEmptyString);
        //assert
        assertFalse(isEmptyString);
    }

    @Test
    public void when_empty_string_it_will_return_true(){
        //arrange
        String emptyString = "";
        //act
        boolean isEmptyString = stringUtil.isEmpty(emptyString);
        //assert
        assertTrue(isEmptyString);
    }

    @Test
    public void when_null_string_it_will_return_true(){
        //arrange
        String nullString = null;
        //act
        boolean isEmptyString = stringUtil.isEmpty(nullString);
        //assert
        assertTrue(isEmptyString);
    }

    @Test
    public void when_string_with_space_it_will_return_true(){
        //arrange
        String spaceString = " ";
        //act
        boolean isEmptyString = stringUtil.isEmpty(spaceString);
        //assert
        assertTrue(isEmptyString);
    }
}

Completado! =D

String Util

    public static boolean isEmpty(String str){
        if (str == null){ return true;}
        return str.trim().equals("");
    }

StringUtilTest

/* RETO: 26/02/2019 */
    @Test
    public void test_string_not_empty(){
        Assert.assertFalse(StringUtil.isEmpty("any string"));
    }

    @Test
    public void test_string_empty(){
        Assert.assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void test_string_empty_also_null(){
        Assert.assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void test_string_empty_with_spaces(){
        Assert.assertTrue(StringUtil.isEmpty("  "));
    }

public class StringUtil {
    public static boolean isEmpty(String string){
        return string == null || string.trim().equals("");
    }
}
public class StringUtilTest {

    @Test
    public void is_invalid_when_string_is_empty(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void is_invalid_when_string_is_null() {
        assertTrue(StringUtil.isEmpty(null));
    }
    @Test
    public void is_invalid_when_string_have_spaces() {
        assertTrue(StringUtil.isEmpty("  "));
    }

    @Test
    public void is_string_valid() {
        assertFalse(StringUtil.isEmpty("hello world"));
    }
}
public class StringUtil
{
    public static boolean isEmpty(String str)
    {
        if (str == null || str.trim().length() == 0)
        {
            return true;
        }
        return false;
    }
}
import org.junit.Test;
import static org.junit.Assert.*;

public class StringUtilTest
{
    @Test
    public void when_is_only_double_quotes()
    {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void when_is_quotes_and_spaces()
    {
        assertTrue(StringUtil.isEmpty("   "));
    }

    @Test
    public void when_is_null()
    {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void when_is_string()
    {
        assertFalse(StringUtil.isEmpty("junit"));
    }
}

En clase StringUtil

public static boolean isEmpty(String text) {

    if (text == null || text.equals("") || text.trim().isEmpty()) {
        return true;
    }else {
        return false;
    }     

StringUtil
@Test
public void isString_Con_Valor() {
Assert.assertFalse(StringUtil.isEmpty(“Prueba”));
}

@Test
public void isString_null() {
    Assert.assertTrue(StringUtil.isEmpty(null));
}

@Test
public void isString_Vacio() {
    Assert.assertTrue(StringUtil.isEmpty(""));
}

@Test
public void isString_Con_Espacio() {
    Assert.assertTrue(StringUtil.isEmpty("  "));
}

public static Boolean isEmpty(String str) {
return (str != null && str.trim().length() > 0) ? true : false;
}

Reto1

public class Reto1 {
    public static boolean isEmpty(String str) {
        //si el tamaño del String es cero (cadena vacía), return true, sino, return false
        return str == null || str.trim().length() == 0;
    }
}

Reto1Test

public class Reto1Test {
    
    @Test
    public void test_any_string() {
        assertFalse(Reto1.isEmpty("Carlos"));
    }
    
    @Test
    public void test_empty_string() {
        assertTrue(Reto1.isEmpty(""));
    }
    
    @Test
    public void test_null_string() {
        assertTrue(Reto1.isEmpty(null));
    }
    
    @Test
    public void test_space_string() {
        assertTrue(Reto1.isEmpty(" "));
    }
}

Clase StringUtil

public class StringUtil {
    
    public static boolean isEmpty(String str) {
        
        if(str != null && !str.isEmpty() && !str.trim().isEmpty()) {
            return true;
        }else{
            return false;
        }
        
    }
    
}

Clase StringUtilTest

public class StringUtilTest {  

    @Test
    public void string_no_es_vacio() {
        
        boolean result= StringUtil.isEmpty(" Hola Mundo   ");
        
        assertTrue(result);
    }
    
    @Test
    public void string_es_vacio() {
        
        boolean result= StringUtil.isEmpty("");
        
        assertFalse(result);
    }
    
    @Test
    public void string_es_null() {
        
        boolean result= StringUtil.isEmpty(null);
        
        assertFalse(result);
    }
    
    @Test
    public void string_con_espacios() {
        
        boolean result= StringUtil.isEmpty("        ");
        
        assertFalse(result);
    }
    
    
    
}
```js public class IsEmptyUtil { public static boolean isEmpty(String str){ return str == null || str.isBlank(); } } ``````js public class IsEmptyUtilTest { @Test public void if_string_is_empty() { assertTrue(IsEmptyUtil.isEmpty("")); } @Test public void if_string_is_null() { assertTrue(IsEmptyUtil.isEmpty(null)); } @Test public void if_string_not_empty() { assertFalse(IsEmptyUtil.isEmpty("abcde")); } } ```
Excelente curso, se aprende mucho ![](https://static.platzi.com/media/user_upload/image-a4a37647-fa60-44ee-9839-76e7f309f7ab.jpg) ![](https://static.platzi.com/media/user_upload/image-50b37b77-1155-4b7d-80d6-5cf3aa0e8ed1.jpg)
//Archivo StringUtil2.java package com.platzi.javatests; import org.junit.Test; import static org.junit.Assert.\*; public class StringUtil2Test { @Test public void prueba\_string\_no\_esta\_vacio(){ *assertFalse*(StringUtil2.*isEmpty*("jackson")); } @Test public void prueba\_string\_es\_vacio(){ *assertTrue*(StringUtil2.*isEmpty*("")); } @Test public void prueba\_string\_es\_nulo(){ *assertTrue*(StringUtil2.*isEmpty*(null)); } @Test public void prueba\_string\_espacio\_en\_blanco(){ *assertTrue*(StringUtil2.*isEmpty*(" ")); } } //Archivo StringUtil2Test.java package com.platzi.javatests; import org.junit.Test; import static org.junit.Assert.\*; public class StringUtil2Test { @Test public void prueba\_string\_no\_esta\_vacio(){ *assertFalse*(StringUtil2.*isEmpty*("jackson")); } @Test public void prueba\_string\_es\_vacio(){ *assertTrue*(StringUtil2.*isEmpty*("")); } @Test public void prueba\_string\_es\_nulo(){ *assertTrue*(StringUtil2.*isEmpty*(null)); } @Test public void prueba\_string\_espacio\_en\_blanco(){ *assertTrue*(StringUtil2.*isEmpty*(" ")); } }
*public class* StringUtil { *public static boolean* isEmpty (String str) { *return* str == *null* || str.trim().isEmpty(); } } *public class* StringUtilTest { @Test *public void* string\_not\_empty() { *assertEquals*(*false*, *isEmpty*("hola")); } @Test *public void* quotation\_isEmpty(){ *assertEquals*(*true*, *isEmpty*("")); } @Test *public void* null\_isEmpty(){ *assertEquals*(*true*, *isEmpty*(*null*)); } @Test *public void* string\_with\_spaces\_isEmpty() { *assertEquals*(*true*, *isEmpty*(" ")); } }
![](https://static.platzi.com/media/user_upload/image-c1b2f9d3-1e9c-42f4-9b3e-341db2b7972a.jpg)
public static boolean isEmpty(<u>String</u> str) { return str == null || tr.trim().length() <= 0; } @Test public void not\_empty() { assertFalse(StringUtil.isEmpty("word")); } @Test public void empty\_string() { assertTrue(StringUtil.isEmpty("")); } @Test public void white\_space() { assertTrue(StringUtil.isEmpty(" ")); } @Test public void null\_value() { assertTrue(StringUtil.isEmpty(null)); }
Test ![](https://static.platzi.com/media/user_upload/image-9df3e32b-3cde-4d79-a3c9-25d999706e98.jpg) Method ![](https://static.platzi.com/media/user_upload/image-3f573304-fb72-4c85-b534-76656055d2e0.jpg)
```java package com.javatest; import org.junit.*; import java.util.Random; import static org.junit.Assert.*; public class Main { @Test public void is_empty() { final String res = testThis(""); assertEquals("",res); } @Test public void is_not_empty(){ assertFalse(testThis("hola").isEmpty()); } @Test public void is_not_null(){ assertNotNull(testThis("hola")); } @Test public void is_not_white_space(){ assertTrue(testThis(" ").length() ==0); } public static String testThis(String txt){ return txt.trim(); } } ```package com.javatest; import org.junit.\*; import java.util.Random; import static org.junit.Assert.\*; public class Main { @Test public void is\_empty() { final String res = *testThis*(""); *assertEquals*("",res); } @Test public void is\_not\_empty(){ *assertFalse*(*testThis*("hola").isEmpty()); } @Test public void is\_not\_null(){ *assertNotNull*(*testThis*("hola")); } @Test public void is\_not\_white\_space(){ *assertTrue*(*testThis*(" ").length() ==0); } public static String testThis(String txt){ return txt.trim(); } }
```js public static boolean isEmpty(String str) { return str == null || str.trim().isEmpty(); } ``````js @Test public void should_return_true_if_string_is_null() { assertTrue(StringUtil.isEmpty(null)); } @Test public void should_return_true_if_string_is_empty() { assertTrue(StringUtil.isEmpty("")); } @Test public void should_return_true_if_string_is_only_spaces() { assertTrue(StringUtil.isEmpty(" ")); } @Test public void should_return_false_if_string_is_not_empty() { assertFalse(StringUtil.isEmpty("not empty")); } ```
```js public static boolean isEmpty(String str) { return str == null || str.trim().isEmpty(); } ```***Tests:*** ```js @Test public void should_return_true_if_string_is_null() { assertTrue(StringUtil.isEmpty(null)); } @Test public void should_return_true_if_string_is_empty() { assertTrue(StringUtil.isEmpty("")); } @Test public void should_return_true_if_string_is_only_spaces() { assertTrue(StringUtil.isEmpty(" ")); } @Test public void should_return_false_if_string_is_not_empty() { assertFalse(StringUtil.isEmpty("not empty")); } ```
public class StringUtil { public static boolean isEmpty(String str) { return str == null || str.isBlank(); } } class StringUtilTest { @Test public void str\_nulo(){ *assertTrue*(StringUtil.*isEmpty*(null)); } @Test public void str\_comillas(){ *assertTrue*(StringUtil.*isEmpty*("")); } @Test public void str\_espacios(){ *assertTrue*(StringUtil.*isEmpty*(" ")); } @Test public void str\_valido(){ *assertFalse*(StringUtil.*isEmpty*("Hola")); } }
```java public static boolean isEmpty(String str) { if(str == null || str.length() == 0 || str.isEmpty() || str.trim().isEmpty()) { return true; } return false; } @Test public void cadena_lleno() { boolean valor = StringUtil.isEmpty("Hola"); assertEquals( false, valor); } @Test public void cadena_vacio() { boolean valor = StringUtil.isEmpty(""); assertEquals( true, valor); } @Test public void cadena_null() { boolean valor = StringUtil.isEmpty( null); assertEquals( true, valor); } @Test public void cadena_spacio() { boolean valor = StringUtil.isEmpty(" "); assertEquals( true, valor); } ```public static boolean isEmpty(String str) { if(str == null || str.length() == 0 || str.isEmpty() || str.trim().isEmpty()) { return true; } return false; }
Solución 2024 ```java public class StringUtil { public static boolean isEmpty(String str) { return (str == null) || (str.trim().length() == 0); } } ```**Tests con JUnits** ```java public class StringUtilTest { @Test public void strIsNoEmpty() { boolean result = StringUtil.isEmpty("HolaMundo"); Assert.assertFalse(result); } @Test public void strIsEmptyWithNoSpaces() { boolean result = StringUtil.isEmpty(""); Assert.assertTrue(result); } @Test public void strIsEmptyWithAnySpaces() { boolean result = StringUtil.isEmpty(" "); Assert.assertTrue(result); } @Test public void strNullIsEmpty() { boolean result = StringUtil.isEmpty(null); Assert.assertTrue(result); } } ```
public boolean isEmpty(String str) { if (str == null) { return true; } return str.isEmpty() || str.trim().isEmpty(); } @Test public void testIsEmpty() { System.out.println("IsEmpty"); StringUtil instance = new StringUtil(); assertTrue(instance.isEmpty(null)); assertTrue(instance.isEmpty("")); assertTrue(instance.isEmpty(" ")); assertFalse(instance.isEmpty(" a ")); }
```js public class StringUtila { public static boolean isEmpty(String str) { return str == null || str.trim().length()<=0; } } ```public class StringUtila { public static boolean isEmpty(String str) { return str == null || str.trim().length()<=0; } } ```js public class StringUtilTesta { @Test public void StringNoVacio() { String str = "Hola"; Assert.assertFalse(str.isEmpty()); } @Test public void ComillasStringVacio() { String str = ""; Assert.assertTrue(str.isEmpty()); } @Test public void NullStringVacio() { assertTrue(StringUtila.isEmpty(null)); } @Test public void ComillasConEspacioVacio() { assertTrue(StringUtila.isEmpty(" ")); } } ```
Aporte public static boolean isEmpty(String s){ return (s == null || (s.trim().isEmpty())); } pruebas @Test public void string\_is\_not\_empty\_when\_contains\_a\_value(){ *assertFalse*(StringUtil.*isEmpty*("No vacio")); } @Test public void string\_is\_empty\_when\_contains\_just\_spaces(){ *assertTrue*(StringUtil.*isEmpty*(" ")); } @Test public void string\_is\_empty\_when\_empty\_string\_is\_given(){ *assertTrue*(StringUtil.*isEmpty*("")); } @Test public void string\_is\_empty\_when\_null\_value\_is\_given(){ *assertTrue*(StringUtil.*isEmpty*(null)); }
public class StringUtilTest { @Test public void any\_string\_is\_not\_empty(){ String str = "123abc"; *assertFalse*(StringUtil.*isEmpty*(str)); } @Test public void string\_empty\_is\_empty(){ String str = ""; *assertTrue*(StringUtil.*isEmpty*(str)); } @Test public void string\_empty\_withblanks\_isEmpty(){ String str = " "; *assertTrue*("It is Empty", StringUtil.*isEmpty*(str)); } @Test public void string\_null\_isEmpty(){ *assertTrue*(StringUtil.*isEmpty*(null)); } } public class StringUtil { public static boolean isEmpty(String str){ //Verifica si str es nullo, este manejo es por ser Java 8 Optional\<String> test = Optional.*ofNullable*(str); //Si str no esta presente por ser nulo envia true, de lo contrario //Continua con los Tests if(test.isPresent()){ if (str.isEmpty()){ return true; }else if (str.trim().isEmpty()){ return true; }else if(str == null){ return true; }else return false; }else return true; } }
```java public class StringUtil { public static boolean isEmpty(final String str) { if (str == null) { return true; } return str.trim().isEmpty(); } } ``` ```js import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class StringUtilTest { @SuppressWarnings("nls") private String getStringValue() { return "qwerty"; } @SuppressWarnings("nls") private String getStringEmpty() { return ""; } @SuppressWarnings("nls") private String getStringWithSpaces() { return " "; } private String getStringNull() { return null; } @Test void verify_string_is_not_empty() { String strTest = getStringValue(); boolean result = StringUtil.isEmpty(strTest); Assertions.assertFalse(result); } @Test void verify_string_is_empty() { String strTest = getStringEmpty(); boolean result = StringUtil.isEmpty(strTest); Assertions.assertTrue(result); } @Test void verify_null_is_empty() { String strTest = getStringNull(); boolean result = StringUtil.isEmpty(strTest); Assertions.assertTrue(result); } @Test void verify_string_with_spaces_is_empty() { String strTest = getStringWithSpaces(); boolean result = StringUtil.isEmpty(strTest); Assertions.assertTrue(result); } } ```

Aqui mi aporte

public class String2Util {

    public static boolean isEmpty(String str){
        if(str == null || str.trim().equals("")){
            return true;
        } else{
            return false;
        }
    }
}
public class String2UtilTest {

    @Test
    public void isAnyStringEmpty() {
        assertFalse(String2Util.isEmpty("hola"));
    }

    @Test
    public void isCorcheteStringEmpty() {
        assertTrue(String2Util.isEmpty(""));
    }

    @Test
    public void isNullEmpty() {
        assertTrue(String2Util.isEmpty(null));
    }
}
```java // StringUtil.java public class StringUtil { public static boolean isEmpty(String str) { // TODO: return str == null || str.trim().length() <= 0; } } ``` ```java // StringUtilTest.java import org.junit.Test import org.junit.Assert.*; public class StringUtilTest { @Test public void string_is_not_empty() { assertFalse(StringUtil.isEmpty("abcd")); } @Test public void string_is_empty() { assertTrue(StringUtil.isEmpty("")); } @Test public void string_is_null() { assertTrue(StringUtil.isEmpty(null)); } @Test public void string_with_spaces_is_empty() { assertTrue(StringUtil.isEmpty(" ")); } } ```
Método implementado en mi clase StringUtil. public static boolean isEmpty(String str){ if(str == null || str.isEmpty() || str.matches("\[\\\s]+")){ return true; }else { return false; } } TESTS: //Probar que un string cualquiera no es vacío @Test public void no\_es\_vacio() { Assert.*assertFalse*(StringUtil.*isEmpty*("wilmer")); } //Probar que “” es un string vacío @Test public void es\_vacio() { Assert.*assertTrue*(StringUtil.*isEmpty*("")); } //Probar que null también es un string vacío @Test public void null\_es\_vacio() { Assert.*assertTrue*(StringUtil.*isEmpty*(null)); } //Probar que null también es un string vacío @Test public void cadena\_con\_espacios\_es\_vacio() { Assert.*assertTrue*(StringUtil.*isEmpty*(" ")); }

Buenisimo el curso gracias el resto que siga llorando

// Function public static boolean isEmpty(String str) { if ( str == null || str.isBlank()) return true; return false; } // Tests @Test public void stringIsNotEmpty() { *assertFalse*(StringUtil.*isEmpty*("hola")); } @Test public void stringIsEmptyWithEmptyString() { *assertTrue*(StringUtil.*isEmpty*("")); } @Test public void stringIsEmptyWithNullValue() { *assertTrue*(StringUtil.*isEmpty*(null)); } @Test public void stringIsEmptyWithSpace() { *assertTrue*(StringUtil.*isEmpty*(" ")); }
public static boolean isEmpty(String str){ try { return str.isBlank(); }catch(NullPointerException e){ System.*out*.println(e); return true; } } @Test public void string\_is\_not\_empty(){ String str ="hola"; *assertFalse*(StringUtil.*isEmpty*(str)); } @Test public void string\_is\_empty(){ String str =""; *assertTrue*(StringUtil.*isEmpty*(str)); } @Test public void stringNull\_is\_empty(){ String str =null; *assertTrue*(StringUtil.*isEmpty*(str)); } @Test public void stringNull\_has\_spaces(){ String str =" "; *assertTrue*(StringUtil.*isEmpty*(str)); }
```js public static boolean isEmpty(String str){ return str == null || str.trim().isEmpty(); } @Test public void any_string_is_not_empty() { assertFalse(StringUtil.isEmpty("Hola Mundo")); } @Test public void any_string_is_empty() { assertTrue(StringUtil.isEmpty("")); } @Test public void null_string_is_empty() { assertTrue(StringUtil.isEmpty(null)); } @Test public void blank_string_is_empty() { assertTrue(StringUtil.isEmpty(" ")); } ```public static boolean isEmpty(String str){ return str == null || str.trim().isEmpty(); }
`public static boolean isEmpty(String str){` ` return str == null || str.trim().isEmpty();` `}` `@Test` `public void any_string_is_not_empty() {` ` ``assertFalse``(StringUtil.``isEmpty``("Hola Mundo"));` `}` `@Test` `public void any_string_is_empty() {` ` ``assertTrue``(StringUtil.``isEmpty``(""));` `}` `@Test` `public void null_string_is_empty() {` ` ``assertTrue``(StringUtil.``isEmpty``(null));` `}` `@Test` `public void blank_string_is_empty() {` ` ``assertTrue``(StringUtil.``isEmpty``(" "));` `}`

Muchas gracias!

con ayuda de un comentario he realizado este codigo 🎉

@Test
    public void test_string_is_not_empty (){
        assertFalse(StringUtil.isEmpty("matías"));
    }

    @Test
    public void test_quote_is_not_empty (){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void null_is_string_empty (){
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_space_is_empty (){
        assertTrue(StringUtil.isEmpty("  "));
    }
public class StringUtil
{
    public static boolean isEmpty(String str)
    {
        return str == null || str.trim().isEmpty();
    }
}
public class StringUtilTest
{
    @Test
    public void el_String_no_esta_vacio()
    {
        assertFalse(StringUtil.isEmpty("holajaja"));
    }

    @Test
    public void el_String_esta_vacio()
    {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void el_String_es_null()
    {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void el_String_tiene_un_espacio()
    {
        assertTrue(StringUtil.isEmpty(" "));
    }
}
![](https://static.platzi.com/media/user_upload/image-54e7ab92-221d-4189-9b7a-ea26cc505c63.jpg) ![](https://static.platzi.com/media/user_upload/image-fac8b864-e3d9-460e-ab73-787b624394e0.jpg)
StringUtil ```java public static boolean isEmpty(String str){ if (str == null){ return true; } if (str.isEmpty()){ return true; } if (str.matches("[ ]")) { return true; } return false; } ```StringUtilTest ```js @Test public void any_string_is_not_empty() { Assert.assertFalse(StringUtil.isEmpty("hola")); } @Test public void empty_string_is_empty() { Assert.assertTrue(StringUtil.isEmpty("")); } @Test public void null_is_empty() { Assert.assertTrue(StringUtil.isEmpty(null)); } @Test public void string_with_blanks_is_empty() { Assert.assertTrue(StringUtil.isEmpty(" ")); } ```
**//Clase** `public static boolean isEmpty (String str){` ` if (str.isEmpty()){` ` return false;` ` }` ` if (str == null){` ` throw new NullPointerException("Negative times not allowed");` ` }` ` if (str.trim().length() == 0){` ` return false;` ` }` ` return true;` `}` **//Test** `@Test` `public void stringIsNotEmpty() {` ` ``assertTrue``(StringIsEmpty.``isEmpty``("Hello"));` `}` `@Test` `public void stringQuotesAlone() {` ` ``assertFalse``(StringIsEmpty.``isEmpty``(""));` `}` `@Test(expected = NullPointerException.class)` `public void stringIsNull() {` ` StringIsEmpty.``isEmpty``(null);` `}` `@Test` `public void stringWithSpace() {` ` ``assertFalse``(StringIsEmpty.``isEmpty``(" "));` `}`
Por si se quieren pasar de listos mandando la palabra null public static boolean isEmpty(String str){ return str == null || str.trim().replace("null","").isEmpty(); } Los test: @Test public void string\_is\_null() { Assert.*assertTrue*(StringUtil.*isEmpty*(null)); } @Test public void string\_not\_is\_empty(){ Assert.*assertFalse*(StringUtil.*isEmpty*("palabra")); } @Test public void string\_is\_empty(){ Assert.*assertTrue*(StringUtil.*isEmpty*("")); } @Test public void string\_whit\_spaces(){ Assert.*assertTrue*(StringUtil.*isEmpty*(" ")); } @Test public void string\_whit\_word\_null(){ Assert.*assertTrue*(StringUtil.*isEmpty*("null")); }
//Class public static boolean isEmpty(String str){ //Solucion 1 //return str == null || str.trim().equals(""); //Solucion 2 return str == null || str.trim().replace("null", "").isEmpty(); } // Test class public class StringUtilTest { //Probar que un string cualquiera no es vacío @Test public void testNotEmptyString(){ assertFalse(StringUtil.isEmpty("abcde")); } @Test public void testEmptyString(){ assertTrue(StringUtil.isEmpty("")); } @Test public void testNullString(){ assertTrue(StringUtil.isEmpty(null)); } @Test public void testSpacesString(){ assertTrue(StringUtil.isEmpty(" ")); } }
public static boolean isEmpty(String str) {
        return str == null || str.isBlank();
   }
@Test
    void test_empty_string_is_empty() {
        assertTrue(StringUtil.isEmpty(""));
    }
    @Test
    void test_null_string_is_empty() {
        assertTrue(StringUtil.isEmpty(null));
    }
    @Test
    void test_space_string_is_empty() {
        assertTrue(StringUtil.isEmpty(" "));
    }

    @Test
    void test_string_is_not_empty() {
        assertFalse(StringUtil.isEmpty("Test"));
    } 

Clase StringUtil.java

public class StringUtil {


    public static boolean isEmpty(String text) {

        if (text == null) {
            System.out.println(text + " es null");
            return true;
        }

        if (text.trim().isEmpty()) {
            System.out.println("\"" + text + "\" es un texto vacío");
            return true;
        } else{
            System.out.println("El texto es: " + text);
        }


        return false;
    }

}


Tests llevados a cabo:

 public class StringUtilTest {

    @Test
    public void any_string_is_not_empty(){
        assertFalse(StringUtil.isEmpty("Gerson"));
    }

    @Test
    public void no_text_is_an_empty_string(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void null_is_an_empty_string(){
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void space_is_an_empty_string(){
        assertTrue(StringUtil.isEmpty(" "));
    }
}

Resultado obtenido:

import static org.junit.Assert.*;

import org.junit.Test;

public class StringUtilTest {

public StringUtil stringUtil = new StringUtil();

@Test
public void isEmpty() {
    assertTrue(stringUtil.isEmpty(""));
}

@Test
public void isNotEmpty() {
    assertFalse(stringUtil.isEmpty("asd"));
}

@Test
public void isNull() {
    assertTrue(stringUtil.isEmpty(null));
}

@Test
public void haveEmptySpaces() {
    assertTrue(stringUtil.isEmpty("entro a la casa"));
}

}

public static boolean isEmpty(String str){

  if(str == null || str.contains(" ")){
      return true;
  }

  return str.isEmpty() ? true : false;

}

Test

package org.example;

import org.junit.Test;

import static org.junit.jupiter.api.Assertions.*;

public class StringUtilTest {
    @Test
    public void check_that_a_text_is_empty() {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void a_text_with_any_content_is_not_empty() {
        assertFalse(StringUtil.isEmpty("a"));
    }

    @Test
    public void is_receive_nothing_is_empty() {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void a_text_with_spaces_and_without_content_is_empty() {
        assertTrue(StringUtil.isEmpty(" "));
    }
}

Código

package org.example;

public class StringUtil {
    public static boolean isEmpty(String text) {
        return text == null || text.isBlank();
    }
}
 
//CLASS

public class StringUtil {
    public static boolean isEmpty(String str) {
        // si es null devolvemos true
        if (str == null) {
            return true;
        }
        //Eliminamos los espacios al principio y al final de la cadena de texto
        str = str.trim();

        if (str.equals("")) {
            return true;
        }
        return false;
    }
}



// TEST

public class StringUtilTest {

    @Test
    public void empty_string() {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_no_empty() {
        assertFalse(StringUtil.isEmpty("HolaMundo!"));
    }

    @Test
    public void string_equals_null() {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_only_spaces() {
        assertTrue(StringUtil.isEmpty("   "));
    }

}

Función

public static boolean isEmpty(String str) {
        return str==null || str.trim().isEmpty();
    }

Tests

@Test
    public void string_is_not_empty(){
        assertFalse(StringUtil.isEmpty("Hola"));
    }
    @Test
    public void empty_quote_is_empty(){
        assertTrue(StringUtil.isEmpty(""));
    }
    @Test
    public void null_is_empty(){
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void spaces_is_empty(){
        assertTrue(StringUtil.isEmpty(" "));
    }
public static boolean isEmpty(String str){

        return str == null || str.trim().isEmpty();
}
public static boolean isEmpty(String str){

        if(str == null || str.contains(" ")){
            return true;
        }

        return str.isEmpty() ? true : false;

    }
package com.platzi;
import com.platzi.*;
import static org.junit.Assert.*;

import org.junit.Test;

public class StringUtilTest {

    public StringUtil stringUtil = new StringUtil();


    @Test
    public void isEmpty() {

        assertTrue(stringUtil.isEmpty(""));

    }

    @Test
    public void isNotEmpty() {

        assertFalse(stringUtil.isEmpty("asd"));

    }

    @Test
    public void isNull() {

        assertTrue(stringUtil.isEmpty(null));

    }

    @Test
    public void haveEmptySpaces() {

        assertTrue(stringUtil.isEmpty("entro a la casa"));

    }
}
public static boolean isEmpty(String str){
        if (str == null || str.length() == 0 || str.trim() != str) {
            return true;
        }else {
            return false;
        }
    }

@Test
    public void string_not_empty() {
        assertFalse(StringUtil.isEmpty("dsfdf"));
    }

    @Test
    public void string_is_empty() {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_null_is_empty() {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_with_space_is_empty() {
        assertTrue(StringUtil.isEmpty(" "));
    }
    public static boolean isEmpty(String str) {

        return str == null || str.trim().equals("") ;

    }
    @Test
    public void isEmptyVacioTest(){
        Assert.assertTrue(StringUtil.isEmpty(""));
    }
    
    @Test
    public void isEmptyNullTest(){
        Assert.assertTrue(StringUtil.isEmpty(null));
    }
    
    @Test
    public void isEmptyEspaciadoTest(){
        Assert.assertTrue(StringUtil.isEmpty(" "));
    }
    
    @Test
    public void isEmptyTest(){
        Assert.assertFalse(StringUtil.isEmpty("Hola"));
    }
public static boolean isEmpty(String str){

        if(str == null || str.trim().isEmpty()){
            return true;
        }

        return false;
}
public class StringUtilTest {

    @Test
    public void string_is_not_empty() {
        assertFalse(StringUtil.isEmpty("x"));
    }

    @Test
    public void string_is_empty(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_is_null(){
        assertTrue(StringUtil.isEmpty(null));
    }

}

Respusta RETO1

StringUtils.class 
    public static Boolean isEmpty(String cadena){
        return cadena == null || cadena.trim().length() == 0;
    }


StringUtilsTest
    @Test
    public void word_is_not_empty(){
        assertFalse(StringUtils.isEmpty("Maverick"));
    }

    @Test
    public void quotation_marks_is_empty(){
        assertTrue(StringUtils.isEmpty(""));
    }

    @Test
    public void space_is_empty(){
        assertTrue(StringUtils.isEmpty(" "));
    }

    @Test
    public void null_is_empty(){
        assertTrue(StringUtils.isEmpty(null));
    }

public static boolean isEmpty(String str) {
        return (str == null || str.trim().length() == 0);
    }


 @Test
    public void testNotEmptyString() {
        Assert.assertFalse(StringUtil.isEmpty("Hola"));
    }

    @Test
    public void testEmptyString() {
        Assert.assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void testNullString() {
        Assert.assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void testSpacesString() {
        Assert.assertTrue(StringUtil.isEmpty(" "));
    }

public class StringUtil {
public static boolean isEmpty(String str) {
return (str.isEmpty() || str == null || str.trim().length() < 1);
}
}

public class StringUtilTest {
@Test
public void stringIsNotNull(){
StringUtil isNullTest = new StringUtil();
boolean is_null = isNullTest.isEmpty(“Is null”);
assertEquals(false, is_null);
}

@Test
public void stringIsNull(){
    StringUtil isNullTest = new StringUtil();
    boolean is_null = isNullTest.isEmpty(" ");
    assertEquals(true, is_null);
}

}

El método isBlank() comprueba sí el string es vacío o contiene solo espacios en blanco, a diferencia de isEmpty(), el cual comprueba que la longitud del string sea 0 para retornar true, por lo que con tan solo un espacio en blanco retornará false puesto que como sabemos, en programación el espacio en blanco es un “caracter”

@Test
    void stringNoEsVacio() {
        assertFalse(StringUtil.isEmpty("hola"));
    }

    @Test
    void stringEsVacio() {
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    void nullEsVacio() {
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    void stringConEspaciosEsVacio() {
        assertTrue(StringUtil.isEmpty("   "));
    }
public static boolean isEmpty(String str) {
        return str == null || str.trim().equals("");
    }

Yo estoy utilizando jUnit5

StringUtil

 public static boolean isEmpty(String str) {
        return str == null || str.trim().equals("");
    }

StringUtilTest

 @Test
    @DisplayName("Cualquier cadena no es vacia")
    void empty1(){
        assertFalse(StringUtil.isEmpty(" 2;asdk l "));
    }
    @Test
    @DisplayName("Cadena vacia devuelve true")
    void empty2(){
        assertTrue(StringUtil.isEmpty(""));
    }
    @Test
    @DisplayName("Cadena null es vacia")
    void empty3(){
        assertTrue(StringUtil.isEmpty(null));
    }
    @Test
    @DisplayName("Cadena de espacios es vacia")
    void empty4(){
        assertTrue(StringUtil.isEmpty("   "));
    }

Utilizando expresiones regulares seria:

Funcion:

public static boolean isEmpty(String str){
        return str == null || str.matches("") || str.matches("\\s+");
    }

Tests:

@Test
    public void isEmpty_when_string_is_just_quotes(){
        String actual = "";
        Assertions.assertTrue(StringUtil.isEmpty(actual));
    }

    @Test
    public void isEmpty_when_string_is_just_one_white_space(){
        String actual = " ";
        Assertions.assertTrue(StringUtil.isEmpty(actual));
    }

    @Test
    public void isEmpty_when_string_is_just_white_spaces(){
        String actual = "           ";
        Assertions.assertTrue(StringUtil.isEmpty(actual));
    }

    @Test
    public void isEmpty_when_string_is_null(){
        String actual = null;
        Assertions.assertTrue(StringUtil.isEmpty(actual));
    }

    @Test
    public void not_isEmpty_when_have_text(){
        String actual = "Text-For-the-test";
        Assertions.assertFalse(StringUtil.isEmpty(actual));
    }

    @Test
    public void not_isEmpty_when_have_text_and_spaces(){
        String actual = "   Text For the test   !    ";
        Assertions.assertFalse(StringUtil.isEmpty(actual));
    }

PD: Utilizando JUnit5.

Test:

    @Test
    public void quotes_is_empty() {
        boolean result = StringUtil.isEmpty("");
       Assert.assertTrue(result);
    }

    @Test
    public void string_is_not_empty() {
        boolean result = StringUtil.isEmpty("karen");
        Assert.assertFalse(result);
    }

    @Test
    public void null_is_empty() {
        boolean result = StringUtil.isEmpty(null);
        Assert.assertTrue(result);
    }

    @Test
    public void blank_is_empty() {
        boolean result = StringUtil.isEmpty("     ");
        Assert.assertTrue(result);
    }

codigo:

public static boolean isEmpty(String str){
        if(str == null || str.isEmpty() || str.trim().isEmpty()){
            return true;
        }
        return false;
    }

StringUtil.java

package com.platzi.javatests.util;

public class StringUtil {
    
    public static boolean isEmpty(String str){
        if(str==null){
            return true;
        }
        return str.trim().isEmpty();
    }
}

StringUtilTest.java

package com.platzi.javatests.util;

import org.junit.Assert;
import org.junit.Test;

public class StringUtilTest {
    @Test
    public void testNotEmpty(){
        Assert.assertFalse(StringUtil.isEmpty("a"));
    }
    @Test
    public void testEmpty(){
        Assert.assertTrue(StringUtil.isEmpty(""));
    }
    @Test
    public void testNull(){
        Assert.assertTrue(StringUtil.isEmpty(null));
    }
    @Test
    public void testBankSpace(){
        Assert.assertTrue(StringUtil.isEmpty(" "));
    }

}

–StringUtil
public static boolean isEmpty(String str) {
return str == null || str.trim().length() == 0;
}

– StringUtilTest
@Test
public void word_is_not_empty() {
assertFalse(StringUtil.isEmpty(“Word”));
}

@Test
public void quotation_marks_is_empty() {
    assertTrue(StringUtil.isEmpty(""));
}

@Test
public void space_is_Empty() {
    String str = new String(" ");
    assertTrue(StringUtil.isEmpty(str));
}

@Test
public void null_is_empty() {
    assertTrue(StringUtil.isEmpty(null));
}

El método en sí es bastante sencillo:

    public static boolean isEmpty(String str){
        return str == null || str.trim().length() == 0;
    } 

Estos tests son utilizando JUnit5:

    @Mock
    StringUtil stringUtil;

    @Test
    public void isempty_null_string_test(){
        assertTrue(stringUtil.isEmpty(null));
    }

    @Test
    public void isempty_spaces_string_test(){
        assertTrue(stringUtil.isEmpty("        "));
    }

    @Test
    public void isempty_string_test(){
        assertTrue(stringUtil.isEmpty(""));
    }

    @Test
    public void isempty_not_string_test(){
        assertFalse(stringUtil.isEmpty("This String is not empty"));
    }
@Test
    public void string_is_not_empty() {
        Assert.assertFalse(StringUtil.isEmpty("Gabriel"));
    }

    @Test
    public void string_is_empty(){
        Assert.assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_is_null(){
        Assert.assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_has_spaces(){
        Assert.assertTrue(StringUtil.isEmpty(" "));
    }

public static boolean isEmpty(String str){
return Objects.isNull(str) || str.trim().isEmpty();
}

public static boolean isEmpty(String str){
boolean isEmpty;
if(str.equals("") || str.equals(null) || str.trim().equals("")){
isEmpty = true;
}else{
isEmpty = false;
}
}

@Mockito
StringUtil stringUtil;

@Before
public void setUp()[
stringUtil = new StringUtil();
}
public void isEmptyTest(){

String prueba = “”;
String nulo = null;
String prueba2 = " ";
Mockito.when(stringUtil.isEmpty(prueba).thenReturn(true));
Mockito.when(stringUtil.isEmpty(nulo).thenReturn(true));
Mockito.when(stringUtil.isEmpty(prueba2).thenReturn(true));
}

package com.platzi.javatest.util;

import java.util.Objects;

public class StringUtil {

    public static boolean isEmpty(String str) {
        return Objects.isNull(str) || str.trim().length() == 0;
    }
}
package com.platzi.javatest.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class StringUtilTest {

    @Test
    public void word_is_not_empty(){
        assertFalse(StringUtil.isEmpty("Palabra"));
    }

    @Test
    public void quotationMarks_is_Empty(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void space_is_Empty(){
        String str = new String(" ");
        assertTrue(StringUtil.isEmpty(str));
    }

    @Test
    public void multiple_space_is_Empty(){
        String str = new String("      ");
        assertTrue(StringUtil.isEmpty(str));
    }

    @Test
    public void null_is_empty(){
        assertTrue(StringUtil.isEmpty(null));
    }
}

Mi solución realizada con regEx

public class StringUtil {
    public static boolean isEmpty(String str) {
        if (str == null || str.matches("\\s+|^$")) {
            return true;
        }
        return false;
    }
}
public static boolean isEmpty(String str) {

		return str == null || str.isBlank();
	}

@Test
	public void is_not_empty() {
		assertFalse(StringUtil.isEmpty("Hola Mundo"));
	}

	@Test
	public void empty_string_is_empty() {
		assertTrue(StringUtil.isEmpty(""));
	}

	@Test
	public void null_is_empty() {
		assertTrue(StringUtil.isEmpty(null));
	}

	@Test
	public void only_blank_spaces_is_empty() {
		assertTrue(StringUtil.isEmpty("    "));
	}

Mi respuesta:

Mi solución

StringUtil

public static boolean isEmpty(String str) {
    return str == null ? true : str.trim().isEmpty();
}

StringUtilTest

@Test
public void isEmpty_whith_null() {
    assertTrue(StringUtil.isEmpty((null)));
}

@Test
public void isEmpty_whith_empty_quotes() {
    assertTrue(StringUtil.isEmpty(("")));
}

@Test
public void isEmpty_whith_blank_space() {
    assertTrue(StringUtil.isEmpty(("   ")));
}

@Test
public void isEmpty_false() {
    assertFalse(StringUtil.isEmpty(("Una Cadena De Ejemplo")));
}

Reto1:
@Test
public void isEmpty() {
String str=null;
boolean resultado;
resultado=validateString(str);
if(resultado == true){
Assert.assertTrue(resultado=true);

    } else {
        Assert.assertFalse(resultado=false);
    }

}

public boolean validateString(String str)
{
    boolean bandera = true;
    if (str==null || str.trim().length() <= 0)
    {
    bandera =false;
    }
    return bandera;
}

intente comparar str antes y despues del trim si cambia es por que no estaba vacio.

 public static boolean isEmpty(String str){
        if(str == null){
            return true;
        }

        if(str.equals("")){
            return  true;
        }

        if(str.trim().length() > str.length()){
            return  true;
        }

        return false;
    }
  @Test
    public void is_empty_null(){
        assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void is_not_empty_string(){
        assertFalse(StringUtil.isEmpty("qwerty"));
    }

   @Test
    public void is_empty_string(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void is_empty_string_wth_space(){
        assertFalse(StringUtil.isEmpty(" "));
    }```

StringUtil

public static boolean isEmpty(String str) {
        return str == null || str.trim().length() == 0;
 }

StringUtilTest

    @Test()
    public void string_is_not_empty() {
        String str = "test";
        assertFalse(StringUtil.isEmpty(str));
    }

    @Test()
    public void string_is_empty() {
        String str = "";
        assertTrue(StringUtil.isEmpty(str));
    }

    @Test()
    public void null_is_empty() {
        String str = null;
        assertTrue(StringUtil.isEmpty(str));
    }

    @Test()
    public void string_space_is_empty() {
        String str = " ";
        assertTrue(StringUtil.isEmpty(str));
    }

Metodo:

//trim borra los espacio, asi que solo contaria los caracteres
public static boolean isEmpty(String str){
        return str == null || str.trim().length() == 0;
    }

Tests:

    //validar que un string no es vacio
    @Test
    public void stringNotEmpty(){
        Boolean result = StringUtil.isEmpty("hola");
        assertFalse(result);
    }

    //validar que un string es vacio
    @Test
    public void stringEmpty(){
        Boolean result = StringUtil.isEmpty("");
        assertTrue(result);
    }

    //Validar un null
    @Test
    public void stringNull(){
        Boolean result = StringUtil.isEmpty(null);
        assertTrue(result);
    }

    //Validar un string con espacio
    @Test
    public void stringSpace(){
        Boolean result = StringUtil.isEmpty(" ");
        assertTrue(result);
    }
<public static boolean isEmpty(String str){
        return str == null || str.trim().length() == 0 || str.equals(" ") || str.equals("");
    }> 
<@Test
    public void string_is_not_empty() {
        Assert.assertFalse(StringUtil.isEmpty("freddy"));
    }

    @Test
    public void string_is_null() {
        Assert.assertTrue(StringUtil.isEmpty(null));
    }

    @Test
    public void string_is_empty_quote() {
        Assert.assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void string_is_empty() {
        Assert.assertTrue(StringUtil.isEmpty(" "));
    }> 

Mi aporte

public static boolean isEmpty(String args) {
        return args == null || args.trim().length() == 0;
    }
@Test
    public void should(){
        assertFalse(StringUtil.isEmpty("JOSE"));
        assertTrue(StringUtil.isEmpty(""));
        assertTrue(StringUtil.isEmpty("     "));
    }

Util:

package com.platzi.javatests.util;

public class EmptyStringUtil {
    public static boolean isEmpty(String str) {
        return str == null || str.trim().length() == 0;
    }
}

Test:

package com.platzi.javatests.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class EmptyStringUtilTest {

    @Test
    public void isNotEmpty() {
        assertFalse(EmptyStringUtil.isEmpty("ABCD"));
    }

    @Test
    public void isEmptyWithSpace() {
        assertTrue(EmptyStringUtil.isEmpty(" "));
    }

    @Test
    public void isEmpty() {
        assertTrue(EmptyStringUtil.isEmpty(""));
    }

    @Test
    public void isEmptyWhenNull() {
        assertTrue(EmptyStringUtil.isEmpty(null));
    }
}

Implementación

        public static boolean isEmpty(String str) {
            if(str==null){
                throw new IllegalArgumentException("str null not allowed");
            }
            return str.trim().length()==0;
        }

Tests

    @Test
    public void str_is_empty(){
        assertTrue(StringUtil.isEmpty(""));
    }

    @Test
    public void str_is_not_empty(){
        assertFalse(StringUtil.isEmpty("hola"));
    }


    @Test(expected = IllegalArgumentException.class)
    public void str_is_empty_is_null(){
        StringUtil.isEmpty(null);
    }

    @Test
    public void str_is_blank(){
        assertTrue(StringUtil.isEmpty("        "));
    }

METODO

public class StringUtil {

    public static boolean isEmpty(String str) {
        if (str == null)
            throw new NullPointerException("No se permite un valor null");
        return str.trim().length() == 0;
    }
}

TEST

public class StringUtilTest {

    @Test
    public void string_is_blank() {
       assertTrue(isEmpty(" "));
    }

    @Test
    public void string_is_empty() {
        assertTrue(isEmpty(""));
    }

    @Test
    public void string_is_not_blank() {
        assertFalse(isEmpty("hola"));
    }

    @Test(expected = NullPointerException.class)
    public void string_is_null() {
        assertTrue(isEmpty(null));
    }

Estuve a nada de no hacer este ejercicio pero que bueno que lo hice aprendí bastante.

public class StringUtil2 {
    public static boolean isEmpty(String str) {
        if(str == "" || str == null)
        {
            return false;
        }
        else {
            return true;
        }

    }

    public static boolean isEmpty()
    {
        return false;
    }
}

Y la clase test:

class StringUtil2Test {

    @Test
    public void string_is_not_empty()
    {
        Assertions.assertEquals(true, StringUtil2.isEmpty("Algo"));
    }

    @Test
    public void string_is_empty()
    {
        Assertions.assertEquals(false, StringUtil2.isEmpty(""));
    }

    @Test
    public void string_is_null()
    {
        Assertions.assertEquals(false, StringUtil2.isEmpty());
    }

}

Yo use una sobreescritura del metodo isEmpty para que pueda no aceptar parámetros.

Vaya que fue muy interesante poder trabajar en estas funcionalidades

public static boolean isEmpty(String str)
    {

        if(str == null || str.isBlank() || str.isEmpty())
        {
            return true;
        }
        else
        {
            return false;
        }
    }
public class StringUtilTest {
    @Test
    public void string_is_not_empty() {
        String string_value = "1542";
        assertFalse(StringUtil.isEmpty(string_value));
    }

    @Test
    public void string_is_empty() {
        String string_value = "";
        assertTrue(StringUtil.isEmpty(string_value));
    }

    @Test
    public void null_is_empty() {
        String string_value = null;
        assertTrue(StringUtil.isEmpty(string_value));
    }

    @Test
    public void space_is_empty() {
        String string_value = "    ";
        assertTrue(StringUtil.isEmpty(string_value));
    }
}
 public static boolean isEmpty(String response) {
        /*trim() removes whitespace from the string on both sides*/
        if (response == "" || response.trim().length() < 1 || response == null) {
            return true;
        }

        return false;
    }
@Test
    public void whenStringIsNull(){
        assertTrue(StringUtil.isEmpty(null));
    }
    
    public void whenStringjusthasSpace(){
        assertTrue(StringUtil.isEmpty(" "));
    }
    
    public void whenStringIsEmpty(){
        assertTrue(StringUtil.isEmpty(""));
    }