Skip to content

Commit

Permalink
Move null-safe trim from (test) StringHelper to (main) StringUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Mar 15, 2024
1 parent 09305d9 commit 1ae5b96
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 55 deletions.
12 changes: 12 additions & 0 deletions src/main/org/firebirdsql/jaybird/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,17 @@ public static String trimToNull(String value) {
public static boolean isNullOrEmpty(String value) {
return value == null || value.isEmpty();
}

/**
* Null-safe trim.
*
* @param stringToTrim
* String to trim
* @return result of {@code stringToTrim.trim()} (or {@code null} if {@code stringToTrim} was null
* @since 6
*/
public static String trim(String stringToTrim) {
return stringToTrim == null ? null : stringToTrim.trim();
}

}
53 changes: 0 additions & 53 deletions src/test/org/firebirdsql/common/StringHelper.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/test/org/firebirdsql/jaybird/util/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EmptySource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -79,4 +80,18 @@ void testIsNullOrEmpty_nonEmptyYieldsFalse(String value) {
assertFalse(StringUtils.isNullOrEmpty(value));
}

@ParameterizedTest
@CsvSource(useHeadersInDisplayName = true, textBlock = """
input, expectedOutput
,
'', ''
' ', ''
'a ', a
' a', a
' a ', a
""")
void testTrim(String input, String expectedOutput) {
assertEquals(expectedOutput, StringUtils.trim(input));
}

}
4 changes: 2 additions & 2 deletions src/test/org/firebirdsql/management/FBManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.firebirdsql.management;

import org.firebirdsql.common.StringHelper;
import org.firebirdsql.gds.ISCConstants;
import org.firebirdsql.gds.ng.FbDatabase;
import org.firebirdsql.jaybird.util.StringUtils;
import org.firebirdsql.jdbc.FBConnection;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -205,7 +205,7 @@ void testCreate_withDefaultCharacterSet() throws Exception {
ResultSet rs = stmt.executeQuery("select RDB$CHARACTER_SET_NAME from rdb$database")) {

assertTrue(rs.next(), "expected a row");
assertEquals("UTF8", StringHelper.trim(rs.getString(1)), "Unexpected default character set");
assertEquals("UTF8", StringUtils.trim(rs.getString(1)), "Unexpected default character set");
}
} finally {
m.dropDatabase(databasePath, DB_USER, DB_PASSWORD);
Expand Down

0 comments on commit 1ae5b96

Please sign in to comment.