I just started to learn Unit testing.
I would like to Unit test custom date deserializer which looks like this:
CustomDateDeserializer.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class CustomDateDeserializer extends JsonDeserializer {
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Long toParse = p.getLongValue();
SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
format.setTimeZone(TimeZone.getTimeZone("GMT+1"));
String formattedActualDate = format.format(new Date(toParse));
return formattedActualDate;
}
}
What is the best way to test it? Any advice appreciated.