Compra acceso a todo Platzi por 1 a帽o

Antes: $249

Currency
$209/a帽o

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscr铆bete

Termina en:

15D
22H
24M
32S
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 254

Preguntas 3

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

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

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

    }
}

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 鈥渘ull鈥 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(鈥渉ola鈥));
}

@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(鈥淧rueba鈥));
}

@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 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(鈥淚s 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 鈥渃aracter鈥

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

}

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

鈥 StringUtilTest
@Test
public void word_is_not_empty() {
assertFalse(StringUtil.isEmpty(鈥淲ord鈥));
}

@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(""));
    }
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 = "Jos茅 Ignacio Ruiz";
        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));
    }

@Test
public void string_no_conteint_space() {
assertTrue(StringUtil.isEmpety(""));
}

@Test
public void string_conteint_space() {
    assertTrue(StringUtil.isEmpety(" "));
}

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

@Test
public void string_contein_element() {
    assertFalse(StringUtil.isEmpety("Hello"));
}

public static boolean isEmpety(String str) {
return Strings.nullToEmpty(str).trim().isEmpty();
}

Util:

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

Test:

@Test
    public void not_empty_string() {
        assertFalse(this.stringUtil.isEmpty("hola"));
    }

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

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

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

publicstaticbooleanisEmpty(String str){
return str == null || str.trim().length() <= 0;
}

@Test
publicvoidword_is_not_empty(){
assertFalse(StringUtil.isEmpty(鈥淧alabra鈥));
}

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

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

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

Dos formas
Metodo forma 1

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

Metodo forma 2

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

Test

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

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

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

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

A continuaci贸n el c贸digo de la funci贸n implementada en StringUtil


  public static boolean isEmpty(String str) {

        if (str == null) {
            return true;
        } else if (str.trim().length() == 0) {
            return true;
        } else {
            return false;
        }
    }


A continuaci贸n, los test implementados

  // isEmpty();
    @Test
    public void isEmpty_is_not_empty() {
        Assert.assertFalse(StringUtil.isEmpty("Texto ingresado"));
    }

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

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

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


// class
public class StringUtil {
    public static boolean isEmpty(String url){
        return url == null || url.trim().isEmpty();
    }


// test

public class StringUtilTest {

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

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

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

    @Test
    public void stringNotEmpty(){
        Assert.assertFalse(StringUtil.isEmpty("osdijf"));
    }
}

public static boolean isEmpty(String string){
boolean resultado = false;

    if (string == null || string.trim().length() == 0){
        resultado = true;
    }

    return resultado;
}

public class StringUtilTest {
@Test
public void isEmpty_case_null(){
boolean result = StringUtil.isEmpty(null);
assertTrue(result);
}

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

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

@Test
public void isEmpty_case_string(){
    boolean result = StringUtil.isEmpty(" perro");
    assertFalse(result);
}

}

RETO #1:

package me.javatest.util;

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

package me.javatest.util;

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

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class StringUtilTest {

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

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

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

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

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

public class StringUtilTest {

@Nested
private String srt;
private StringUtil stringUtil;

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

@Test
public void isEmptyNull() {
    srt = null;

    boolean resul = stringUtil.isEmpty(srt);

    Assert.assertTrue(resul);
}

@Test
public void isNotEmpty() {
    srt = "Hello Word";

    boolean resul = stringUtil.isEmpty(srt);

    Assert.assertFalse(resul);
}

@Test
public void isEmpty() {
    srt = "";

    boolean resul = stringUtil.isEmpty(srt);

    Assert.assertTrue(resul);
}

@Test
public void isEmptyTrim() {
    srt = " Hello Word ";

    boolean resul = stringUtil.isEmpty(srt);

    Assert.assertTrue(resul);
}

}

  public static boolean isEmpty(String str){

        return str == null || str.length() == 0 || str.trim() == "";

    }

Metodo:

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

tests:

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

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

    @Test
    public void when_str_isNull() {
        assertTrue(StringEmptyUtil.isEmpty(null));
    }

    @Test
    public void when_str_isString() {
        assertFalse(StringEmptyUtil.isEmpty("word"));
    }
package com.javatest.util;

public class StringUtil {

    public static boolean isEmpty(String str){
        return str == null || str.matches("^\\s+$|^$");
    }
}
///////////////////////////////////////////////
package com.javatest.util;
import org.junit.Test;

import static org.junit.Assert.*;

public class StringUtilTest {

    @Test
    public void string_is_not_empty() {
        assertFalse(StringUtil.isEmpty("Tobias"));
    }
    @Test
    public void string_is_empty_with_space() {
        assertTrue(StringUtil.isEmpty(" "));
    }

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

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

Implementaci贸n del m茅todo

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

Test:

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

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

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

    @Test
    public void isEmpty_string_not_empty(){
        assertFalse(StringUtil.isEmpty("shba"));
    }

Practica 馃捇

M茅todo en StringUtil.java

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

StringUtilTest.java

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

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

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

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

public class StringUtilReto1 {

public static boolean isEmpty(String cadena) {

    if (cadena == null) {
        return true;
    }
    if (cadena.trim().equals("")) {
        return true;
    }

    return false;


}

}

import org.junit.Test;

import static org.junit.Assert.*;

public class StringUtilReto1Test {

@Test
public void cadenaCualquieraNoEsVacio() {
    assertFalse(StringUtilReto1.isEmpty("abddesf"));
}


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

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

@Test
public void cadenaNulaEsVacio() {
    assertTrue(StringUtilReto1.isEmpty(null));
}

}

    public static boolean isEmpty(String str) {
        if (str == null) {
            return true;
        }
        return str.trim().isEmpty();
    }
//Comprobar valores vac铆os o nulos
    @Test
    public  void String_is_Empty() {
        assertTrue(StringU.isEmpty(""));
    }
    @Test
    public  void String_isnt_Empty() {
        assertFalse(StringU.isEmpty(" t "));
    }
    @Test
    public  void String_is_Null() {
        assertTrue(StringU.isEmpty(null));
    }

#isEmpty Method

#Tests

Clase StringUtil:

package com.platzi.javatest.util;

public class StringUtil {
   
    public static Boolean isEmpty(String str){
        boolean empty = false;

        if (str == null){
            empty = true;
        }else if (str.isEmpty()){
            empty = true;
        }else if (str.trim().isEmpty()){
            empty = true;
        }

        return empty;
    }
}

Clase StringUtilTest:

package com.platzi.javatest.util;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;

public class StringUtilTest {

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

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

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

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

Aqui mi aporte:

Metodo isEmpty

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

Tests

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

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

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

package com.test.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class StringUtilTest {
// @Test
// public void testIsEmpty() {

// }

@BeforeClass
public static void setupOnce(){
    System.out.println("setup once before");
}

@AfterClass
public static void endsetupOnce(){
    System.out.println("end setup once before");
}

@Before
public void setup(){
    System.out.println("doing before");
}

@After
public void afterTest(){
    System.out.println("doing after");
}

@Test
public void empty_string() {
    System.out.println("empty string");
    boolean res = StringUtil.isEmpty("");
    assertTrue("the string should be empty", res);
    
}

@Test
public void null_string() {
    System.out.println("empty string");
    boolean res = StringUtil.isEmpty(null);
    assertTrue("the string should be empty", res);
    
}

@Test
public void not_empty_string() {
    System.out.println("not empty string");
    boolean res = StringUtil.isEmpty("asdf");
    assertFalse("the string should be not empty", res);

}

}

Mi aporte.

package com.platzi.util;

public class StringUtilTest {

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

package com.platzi.util;

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

public class StringUtilTestTest {

    @Test
    public void emptyStringValidation() {
        Assert.assertTrue(StringUtilTest.isEmpty(""));
    }

    @Test
    public void nullStringValidation() {
        Assert.assertTrue(StringUtilTest.isEmpty(null));
    }

    @Test
    public void filledStringValidation() {
        Assert.assertFalse(StringUtilTest.isEmpty("Hola"));
    }

    @Test
    public void spaceStringValidation() {
        Assert.assertTrue(StringUtilTest.isEmpty(" "));
    }
}