### Question:
PayloadDeserializer extends StdDeserializer<Payload> { Date getDateFromSeconds(Map<String, JsonNode> tree, String claimName) { JsonNode node = tree.get(claimName); if (node == null || node.isNull()) { return null; } if (!node.canConvertToLong()) { throw new JWTDecodeException(String.format("The claim '%s' contained a non-numeric date value.", claimName)); } final long ms = node.asLong() * 1000; return new Date(ms); } PayloadDeserializer(ObjectReader reader); private  PayloadDeserializer(Class<?> vc, ObjectReader reader); @Override Payload deserialize(JsonParser p, DeserializationContext ctxt);  }### Answer:
@Test public void shouldGetNullDateWhenParsingNullNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); NullNode node = NullNode.getInstance(); tree.put("key", node); Date date = deserializer.getDateFromSeconds(tree, "key"); assertThat(date, is(nullValue())); }
@Test public void shouldGetNullDateWhenParsingNull() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); tree.put("key", null); Date date = deserializer.getDateFromSeconds(tree, "key"); assertThat(date, is(nullValue())); }
@Test public void shouldThrowWhenParsingNonNumericNode() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The claim 'key' contained a non-numeric date value."); Map<String, JsonNode> tree = new HashMap<>(); TextNode node = new TextNode("123456789"); tree.put("key", node); deserializer.getDateFromSeconds(tree, "key"); }
@Test public void shouldGetDateWhenParsingNumericNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); long seconds = 1478627949 / 1000; LongNode node = new LongNode(seconds); tree.put("key", node); Date date = deserializer.getDateFromSeconds(tree, "key"); assertThat(date, is(notNullValue())); assertThat(date.getTime(), is(seconds * 1000)); }
@Test public void shouldGetLargeDateWhenParsingNumericNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); long seconds = Integer.MAX_VALUE + 10000L; LongNode node = new LongNode(seconds); tree.put("key", node); Date date = deserializer.getDateFromSeconds(tree, "key"); assertThat(date, is(notNullValue())); assertThat(date.getTime(), is(seconds * 1000)); assertThat(date.getTime(), is(2147493647L * 1000)); }