I have recently started writing tests in Java and I am having some problem with the tests for the following class. How to write correctly tests for TestDateTimeSerializer class in such a form.
public class TestDateTimeSerializer extends JsonSerializer<LocalDateTime> {
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
@Override
public void serialize(LocalDateTime dt, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
if (dt == null) {
gen.writeNull();
} else {
gen.writeString(dt.format(FORMATTER));
}
}
}
this class is used here
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
public class TestRequest implements ITestResponse {
@JsonProperty("TestID")
private Long testID;
@JsonSerialize(using = TestDateTimeSerializer.class)
private LocalDateTime lastUpdateDate;
}