### Question:
GithubMapper { Optional<GithubIssue> jsonToIssue(String json) { try { return Optional.of(this.objectMapper.readValue(json, TYPE_REFERENCE_TO_GITHUB_ISSUE)); } catch (IOException ex) { log.warn("Unable to cast this json to a github issue : " + json, ex); return Optional.empty(); } }    }### Answer:
@Test public void jsonToIssue_should_return_object() throws IOException { String json = "{\"key\": 42 }"; GithubIssue issue = new GithubIssue(); issue.setNumber(42); issue.setTitle("Test"); issue.setState("open"); Mockito.doReturn(issue).when(this.objectMapper).readValue(json, GithubMapper.TYPE_REFERENCE_TO_GITHUB_ISSUE); Optional<GithubIssue> result = this.cut.jsonToIssue(json); Assertions.assertThat(result).isPresent(); Assertions.assertThat(result.get()).isNotNull(); Assertions.assertThat(result.get().getNumber()).isEqualTo(42L); Assertions.assertThat(result.get().getTitle()).isEqualTo("Test"); Assertions.assertThat(result.get().getState()).isEqualTo("open"); }
@Test public void jsonToIssue_should_return_empty_on_error() throws IOException { String json = "{\"key\": 42 }"; Mockito.doThrow(JsonParseException.class).when(this.objectMapper).readValue(json, GithubMapper.TYPE_REFERENCE_TO_GITHUB_ISSUE); Optional<GithubIssue> result = this.cut.jsonToIssue(json); Assertions.assertThat(result).isNotPresent(); }