JsonExtractor { public RequestT parse(String text) throws JsonExtractException { try { return objectMapper.readValue(text, type); } catch (IOException | IllegalArgumentException e) { throw new JsonExtractException(e); } } JsonExtractor(Class<RequestT> type, Module... modules);  JsonExtractor(Class<RequestT> type, List<Module> modules); RequestT parse(String text);  }
@Test public void parseShouldThrowOnNullInput() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse(null)).isInstanceOf(NullPointerException.class); }
@Test public void parseShouldThrowOnEmptyInput() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnBrokenJson() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"broken")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnEmptyJson() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{}")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnMissingMandatoryField() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"any\"}")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnValidationProblemIllegalArgumentException() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"\",\"field2\":\"any\"}")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnValidationProblemNPE() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":null,\"field2\":\"any\"}")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldThrowOnExtraFiled() throws Exception { assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"value\",\"field2\":\"any\",\"extra\":\"extra\"}")).isInstanceOf(JsonExtractException.class); }
@Test public void parseShouldInstantiateDestinationClass() throws Exception { String field1 = "value1"; String field2 = "value2"; Request request = jsonExtractor.parse("{\"field1\":\"" + field1 + "\",\"field2\":\"" + field2 + "\"}"); assertThat(request.getField1()).isEqualTo(field1); assertThat(request.getField2()).isEqualTo(field2); }