### Question:
TypedQuerySupport { public Optional<T> getSingleResultAsOptional(Query query) { return Optional.ofNullable(getSingleResultOrNull(query)); } TypedQuerySupport(Class<T> clazz); Optional<T> getSingleResultAsOptional(Query query); @SuppressWarnings("unchecked") T getSingleResultOrNull(Query query);  }### Answer:
@Test public void support_returns_an_optional_when_no_result_exception_is_thrown() { Query query = mock(Query.class); when(query.getSingleResult()).thenThrow(new NoResultException("does not exist")); Optional<String> optional = supportToTest.getSingleResultAsOptional(query); assertNotNull(optional); }