### Question:
JWTParser implements JWTPartsParser { @Override public Header parseHeader(String json) throws JWTDecodeException { if (json == null) { throw decodeException(); } try { return headerReader.readValue(json); } catch (IOException e) { throw decodeException(json); } } JWTParser();   JWTParser(ObjectMapper mapper); @Override Payload parsePayload(String json); @Override Header parseHeader(String json);  }### Answer:
@Test public void shouldParseHeader() throws Exception { ObjectMapper mapper = mock(ObjectMapper.class); ObjectReader reader = mock(ObjectReader.class); when(mapper.readerFor(Header.class)).thenReturn(reader); JWTParser parser = new JWTParser(mapper); parser.parseHeader("{}"); verify(reader).readValue("{}"); }
@Test public void shouldThrowOnInvalidHeader() throws Exception { String jsonHeader = "}}"; exception.expect(JWTDecodeException.class); exception.expectMessage(String.format("The string '%s' doesn't have a valid JSON format.", jsonHeader)); Header header = parser.parseHeader(jsonHeader); assertThat(header, is(nullValue())); }
@Test public void shouldThrowWhenConvertingHeaderIfNullJson() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The string 'null' doesn't have a valid JSON format."); parser.parseHeader(null); }
@Test public void shouldThrowWhenConvertingHeaderFromInvalidJson() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The string '}{' doesn't have a valid JSON format."); parser.parseHeader("}{"); }