Skip to content

Commit

Permalink
ci(citrus-base): add string utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Oct 1, 2024
1 parent 057f252 commit c6e553c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ private StringUtils() {

/**
* Helper method checks for non-null and non-blank String.
* @param str
* @return
*/
public static boolean hasText(String str) {
return str != null && !str.isBlank();
}

/**
* String helper checking for isEmpty String and adds null check on given parameter.
* @param str
* @return
*/
public static boolean isEmpty(String str) {
return str == null || str.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.citrusframework.util;

import static org.citrusframework.util.StringUtils.hasText;
import static org.citrusframework.util.StringUtils.isEmpty;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class StringUtilsTest {

@DataProvider
public static Object[][] text() {
return new Object[][]{{"foo"}};
}

@DataProvider
public static Object[][] blankText() {
return new Object[][]{{" "}};
}

@DataProvider
public static Object[][] emptyText() {
return new Object[][]{{null}, {""}};
}

@Test(dataProvider = "text")
public void hasText_returnsTrue(String str) {
assertTrue(hasText(str));
}

@Test(dataProvider = "blankText")
public void hasText_returnsFalse_forBlankText(String str) {
assertFalse(hasText(str));
}
@Test(dataProvider = "emptyText")
public void hasText_returnsFalse_forEmptyText(String str) {
assertFalse(hasText(str));
}

@Test(dataProvider = "emptyText")
public void isEmpty_returnsTrue(String str) {
assertTrue(isEmpty(str));
}

@Test(dataProvider = "text")
public void isEmpty_returnsFalse_forText(String str) {
assertFalse(isEmpty(str));
}

@Test(dataProvider = "blankText")
public void isEmpty_returnsFalse_forBlankText(String str) {
assertFalse(isEmpty(str));
}
}

0 comments on commit c6e553c

Please sign in to comment.