### Question:
ZonedDateTimeDeserializer extends StdDeserializer<ZonedDateTime> { @Override public ZonedDateTime deserialize( JsonParser jsonParser, DeserializationContext deserializationContext ) throws IOException { final String string = jsonParser.getText().trim(); if ( string.isEmpty() ) { return null; } try { if ( DateTimeUtils.containsDateTimeOffset( string ) ) { return ZonedDateTime.parse( string, DateTimeFormatter.ISO_DATE_TIME ); } else { return ZonedDateTime.of( LocalDateTime.parse( string, DateTimeFormatter.ISO_LOCAL_DATE_TIME ), zoneId ); } } catch ( DateTimeParseException e ) { throw JsonMappingException.from( jsonParser, "Could not parse zoned date time: " + string, e ); } } ZonedDateTimeDeserializer(); @Override ZonedDateTime deserialize( JsonParser jsonParser, DeserializationContext deserializationContext );  }### Answer:
@Test public void deserializeEmpty() throws IOException { Mockito.when( jsonParser.getText() ).thenReturn( " " ); Assert.assertNull( deserializer.deserialize( jsonParser, deserializationContext ) ); Mockito.verify( jsonParser ).getText(); Mockito.verifyNoMoreInteractions( jsonParser ); }
@Test public void deserialize() throws IOException { Mockito.when( jsonParser.getText() ).thenReturn( "2018-09-05T17:18:23.123-04:00" ); final ZonedDateTime zonedDateTime = deserializer.deserialize( jsonParser, deserializationContext ); Assert.assertNotNull( zonedDateTime ); Assert.assertEquals( 2018, zonedDateTime.getYear() ); Assert.assertEquals( 9, zonedDateTime.getMonth().getValue() ); Assert.assertEquals( 5, zonedDateTime.getDayOfMonth() ); Assert.assertEquals( 17, zonedDateTime.getHour() ); Assert.assertEquals( 18, zonedDateTime.getMinute() ); Assert.assertEquals( 23, zonedDateTime.getSecond() ); Assert.assertEquals( 123000000, zonedDateTime.getNano() ); Assert.assertEquals( ZoneOffset.ofHours( -4 ), zonedDateTime.getOffset() ); Mockito.verify( jsonParser ).getText(); Mockito.verifyNoMoreInteractions( jsonParser ); }
@Test public void deserializeSystemDefaultZone() throws IOException { Mockito.when( jsonParser.getText() ).thenReturn( "2018-09-05T17:18:23.123" ); final ZonedDateTime zonedDateTime = deserializer.deserialize( jsonParser, deserializationContext ); Assert.assertNotNull( zonedDateTime ); Assert.assertEquals( 2018, zonedDateTime.getYear() ); Assert.assertEquals( 9, zonedDateTime.getMonth().getValue() ); Assert.assertEquals( 5, zonedDateTime.getDayOfMonth() ); Assert.assertEquals( 17, zonedDateTime.getHour() ); Assert.assertEquals( 18, zonedDateTime.getMinute() ); Assert.assertEquals( 23, zonedDateTime.getSecond() ); Assert.assertEquals( 123000000, zonedDateTime.getNano() ); Mockito.verify( jsonParser ).getText(); Mockito.verifyNoMoreInteractions( jsonParser ); }
@Test public void deserializeUtc() throws IOException { Mockito.when( jsonParser.getText() ).thenReturn( "2018-09-05T17:18:23.123Z" ); final ZonedDateTime zonedDateTime = deserializer.deserialize( jsonParser, deserializationContext ); Assert.assertNotNull( zonedDateTime ); Assert.assertEquals( 2018, zonedDateTime.getYear() ); Assert.assertEquals( 9, zonedDateTime.getMonth().getValue() ); Assert.assertEquals( 5, zonedDateTime.getDayOfMonth() ); Assert.assertEquals( 17, zonedDateTime.getHour() ); Assert.assertEquals( 18, zonedDateTime.getMinute() ); Assert.assertEquals( 23, zonedDateTime.getSecond() ); Assert.assertEquals( 123000000, zonedDateTime.getNano() ); Assert.assertEquals( 0, zonedDateTime.getOffset().getTotalSeconds() ); Mockito.verify( jsonParser ).getText(); Mockito.verifyNoMoreInteractions( jsonParser ); }