Skip to content

Commit

Permalink
Add test for nullSafeValue with mapper transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo1999 authored and philwebb committed Dec 11, 2024
1 parent 51c9925 commit 22f527a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.function.Function;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
Expand Down Expand Up @@ -144,6 +145,18 @@ void nullSafeValueWhenClassIsBigIntegerShouldReturnBigInteger() {
assertThat(value).isEqualTo(BigInteger.TEN);
}

@Test
void nullSafeValueWithMapperShouldTransformValue() {
JsonNode node = mock(JsonNode.class);
given(node.textValue()).willReturn("2023-12-01");

java.time.LocalDate result = this.testDeserializer.testNullSafeValue(
node, String.class, java.time.LocalDate::parse
);

assertThat(result).isEqualTo(java.time.LocalDate.of(2023, 12, 1));
}

@Test
void nullSafeValueWhenClassIsUnknownShouldThrowException() {
assertThatIllegalArgumentException()
Expand Down Expand Up @@ -189,6 +202,11 @@ protected T deserializeObject(JsonParser jsonParser, DeserializationContext cont
return null;
}

<D, R> R testNullSafeValue(JsonNode jsonNode, Class<D> type, Function<D, R> mapper) {
return nullSafeValue(jsonNode, type, mapper);
}


<D> D testNullSafeValue(JsonNode jsonNode, Class<D> type) {
return nullSafeValue(jsonNode, type);
}
Expand Down

0 comments on commit 22f527a

Please sign in to comment.