### Question:
FactTypeRequestResolver { public FactTypeEntity resolveFactType(String type) throws AccessDeniedException, InvalidArgumentException { FactTypeEntity typeEntity; try { typeEntity = factManager.getFactType(UUID.fromString(type)); } catch (IllegalArgumentException ignored) { typeEntity = factManager.getFactType(type); } if (typeEntity == null) { throw new InvalidArgumentException().addValidationError("FactType does not exist.", "fact.type.not.exist", "type", type); } if (Objects.equals(typeEntity.getId(), RETRACTION_FACT_TYPE_ID)) { throw new AccessDeniedException("Not allowed to manually use system-defined Retraction FactType. Use /retract endpoint instead."); } return typeEntity; } @Inject  FactTypeRequestResolver(FactManager factManager); FactTypeEntity fetchExistingFactType(UUID id); FactTypeEntity resolveFactType(String type); FactTypeEntity resolveRetractionFactType();  }### Answer:
@Test public void testResolveFactTypeById() throws Exception { UUID type = UUID.randomUUID(); FactTypeEntity entity = new FactTypeEntity(); when(factManager.getFactType(type)).thenReturn(entity); assertSame(entity, resolver.resolveFactType(type.toString())); verify(factManager).getFactType(type); verifyNoMoreInteractions(factManager); }
@Test public void testResolveFactTypeByName() throws Exception { String type = "FactType"; FactTypeEntity entity = new FactTypeEntity(); when(factManager.getFactType(type)).thenReturn(entity); assertSame(entity, resolver.resolveFactType(type)); verify(factManager).getFactType(type); verifyNoMoreInteractions(factManager); }
@Test(expected = InvalidArgumentException.class) public void testResolveFactTypeByIdThrowsException() throws Exception { resolver.resolveFactType(UUID.randomUUID().toString()); }
@Test(expected = InvalidArgumentException.class) public void testResolveFactTypeByNameThrowsException() throws Exception { resolver.resolveFactType("FactType"); }
@Test(expected = AccessDeniedException.class) public void testResolveFactTypeRetractionThrowsException() throws Exception { FactTypeEntity retraction = new FactTypeEntity().setId(RETRACTION_FACT_TYPE_ID); when(factManager.getFactType(retraction.getId())).thenReturn(retraction); resolver.resolveFactType(retraction.getId().toString()); }