### Question:
ObjectTypeRequestResolver { public ObjectTypeEntity fetchExistingObjectType(UUID id) throws ObjectNotFoundException { ObjectTypeEntity entity = objectManager.getObjectType(id); if (entity == null) { throw new ObjectNotFoundException(String.format("ObjectType with id = %s does not exist.", id), "object.type.not.exist", "id", ObjectUtils.ifNotNull(id, Object::toString, "NULL")); } return entity; } @Inject  ObjectTypeRequestResolver(ObjectManager objectManager); ObjectTypeEntity fetchExistingObjectType(UUID id);  }### Answer:
@Test public void testFetchExistingObjectType() throws ObjectNotFoundException { UUID id = UUID.randomUUID(); ObjectTypeEntity entity = new ObjectTypeEntity(); when(objectManager.getObjectType(id)).thenReturn(entity); assertSame(entity, resolver.fetchExistingObjectType(id)); }
@Test public void testFetchExistingObjectTypeFailsWhenMissing(){ ObjectNotFoundException ex = assertThrows(ObjectNotFoundException.class, () -> resolver.fetchExistingObjectType(UUID.randomUUID())); assertEquals("object.type.not.exist", ex.getMessageTemplate()); }