### Question:
OriginByIdResponseResolver implements Function<UUID, Origin> { @Override public Origin apply(UUID id) { if (id == null) return null; return responseCache.computeIfAbsent(id, this::resolveUncached); } @Inject  OriginByIdResponseResolver(OriginResolver originResolver,
                                    OriginResponseConverter originResponseConverter,
                                    Map<UUID, Origin> responseCache); @Override Origin apply(UUID id);  }### Answer:
@Test public void testConvertCachedOrigin() { UUID id = UUID.randomUUID(); Origin model = Origin.builder().build(); responseCache.put(id, model); assertSame(model, converter.apply(id)); verifyNoInteractions(originResolver); verifyNoInteractions(originResponseConverter); }
@Test public void testConvertUncachedOrigin() { UUID id = UUID.randomUUID(); OriginEntity entity = new OriginEntity(); Origin model = Origin.builder().build(); when(originResolver.apply(id)).thenReturn(entity); when(originResponseConverter.apply(entity)).thenReturn(model); assertSame(model, converter.apply(id)); verify(originResolver).apply(id); verify(originResponseConverter).apply(entity); }
@Test public void testConvertUncachedOriginNotAvailable() { UUID id = UUID.randomUUID(); Origin model = converter.apply(id); assertNotNull(model); assertEquals(id, model.getId()); assertEquals("N/A", model.getName()); verify(originResolver).apply(id); verifyNoInteractions(originResponseConverter); }
@Test public void testConvertNullReturnsNull() { assertNull(converter.apply(null)); }