Skip to content

Commit

Permalink
Removed Trim on String -> Character conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kpartlow committed Feb 11, 2024
1 parent 47235c9 commit e931513
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ static Boolean toBoolean(Object from, Converter converter) {
}

static char toCharacter(Object from, Converter converter) {
String str = StringUtilities.trimToNull(asString(from));
if (str == null) {
String str = (String)from;
if (str == null || str.isEmpty()) {
return CommonValues.CHARACTER_ZERO;
}
if (str.length() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static Stream<Arguments> toYear_extremeParams() {
);
}


@ParameterizedTest
@MethodSource("toYear_extremeParams")
void toYear_withExtremeParams_returnsValue(String source, int value) {
Expand All @@ -89,6 +90,31 @@ void toYear_withExtremeParams_returnsValue(String source, int value) {
assertThat(actual).isEqualTo(expected);
}

private static Stream<Arguments> toCharParams() {
return Stream.of(
Arguments.of("0000", '\u0000'),
Arguments.of("65", 'A'),
Arguments.of("\t", '\t'),
Arguments.of("\u0005", '\u0005')
);
}

@ParameterizedTest
@MethodSource("toCharParams")
void toChar(String source, char value) {
char actual = this.converter.convert(source, char.class);
//System.out.println(Integer.toHexString(actual) + " = " + Integer.toHexString(value));
assertThat(actual).isEqualTo(value);
}

@ParameterizedTest
@MethodSource("toCharParams")
void toChar(String source, Character value) {
Character actual = this.converter.convert(source, Character.class);
//System.out.println(Integer.toHexString(actual) + " = " + Integer.toHexString(value));
assertThat(actual).isEqualTo(value);
}

private static Stream<Arguments> toCharSequenceTypes() {
return Stream.of(
Arguments.of(StringBuffer.class),
Expand Down

0 comments on commit e931513

Please sign in to comment.