### Question:
FactTypeByIdResponseResolver implements Function<UUID, FactType> { @Override public FactType apply(UUID id) { if (id == null) return null; return responseCache.computeIfAbsent(id, this::resolveUncached); } @Inject  FactTypeByIdResponseResolver(FactManager factManager,
                                      FactTypeResponseConverter factTypeResponseConverter,
                                      Map<UUID, FactType> responseCache); @Override FactType apply(UUID id);  }### Answer:
@Test public void testConvertCachedFactType() { UUID id = UUID.randomUUID(); FactType model = FactType.builder().build(); responseCache.put(id, model); assertSame(model, converter.apply(id)); verifyNoInteractions(factManager); verifyNoInteractions(factTypeResponseConverter); }
@Test public void testConvertUncachedFactType() { UUID id = UUID.randomUUID(); FactTypeEntity entity = new FactTypeEntity(); FactType model = FactType.builder().build(); when(factManager.getFactType(id)).thenReturn(entity); when(factTypeResponseConverter.apply(entity)).thenReturn(model); assertSame(model, converter.apply(id)); verify(factManager).getFactType(id); verify(factTypeResponseConverter).apply(entity); }
@Test public void testConvertUncachedFactTypeNotAvailable() { UUID id = UUID.randomUUID(); FactType model = converter.apply(id); assertNotNull(model); assertEquals(id, model.getId()); assertEquals("N/A", model.getName()); verify(factManager).getFactType(id); verifyNoInteractions(factTypeResponseConverter); }
@Test public void testConvertNullReturnsNull() { assertNull(converter.apply(null)); }