### Question:
FactTypeResponseConverter implements Function<FactTypeEntity, FactType> { @Override public FactType apply(FactTypeEntity entity) { return convertFactType(entity, false); } @Inject  FactTypeResponseConverter(NamespaceByIdResponseResolver namespaceConverter,
                                   ObjectTypeByIdResponseResolver objectTypeConverter,
                                   FactManager factManager); @Override FactType apply(FactTypeEntity entity);  }### Answer:
@Test public void testConvertFactTypeWithBothSourceAndDestination() { FactTypeEntity.FactObjectBindingDefinition binding1 = new FactTypeEntity.FactObjectBindingDefinition() .setSourceObjectTypeID(UUID.randomUUID()) .setDestinationObjectTypeID(UUID.randomUUID()); FactTypeEntity.FactObjectBindingDefinition binding2 = new FactTypeEntity.FactObjectBindingDefinition() .setSourceObjectTypeID(UUID.randomUUID()) .setDestinationObjectTypeID(UUID.randomUUID()) .setBidirectionalBinding(true); FactTypeEntity entity = createEntity() .addRelevantObjectBinding(binding1) .addRelevantObjectBinding(binding2); FactType model = converter.apply(entity); assertModelCommon(entity, model); assertNotNull(model.getRelevantObjectBindings()); assertRelevantObjectBindings(entity, model); assertNull(model.getRelevantFactBindings()); }
@Test public void testConvertFactTypeWithOnlySource() { FactTypeEntity entity = createEntity() .addRelevantObjectBinding(new FactTypeEntity.FactObjectBindingDefinition().setSourceObjectTypeID(UUID.randomUUID())); FactType model = converter.apply(entity); assertNotNull(model.getRelevantObjectBindings().get(0).getSourceObjectType()); assertNull(model.getRelevantObjectBindings().get(0).getDestinationObjectType()); }
@Test public void testConvertFactTypeWithOnlyDestination() { FactTypeEntity entity = createEntity() .addRelevantObjectBinding(new FactTypeEntity.FactObjectBindingDefinition().setDestinationObjectTypeID(UUID.randomUUID())); FactType model = converter.apply(entity); assertNull(model.getRelevantObjectBindings().get(0).getSourceObjectType()); assertNotNull(model.getRelevantObjectBindings().get(0).getDestinationObjectType()); }
@Test public void testConvertFactTypeWithFactBindings() { FactTypeEntity entity = createEntity() .addRelevantFactBinding(new FactTypeEntity.MetaFactBindingDefinition().setFactTypeID(UUID.randomUUID())) .addRelevantFactBinding(new FactTypeEntity.MetaFactBindingDefinition().setFactTypeID(UUID.randomUUID())); FactType model = converter.apply(entity); assertModelCommon(entity, model); assertNull(model.getRelevantObjectBindings()); assertNotNull(model.getRelevantFactBindings()); assertRelevantFactBindings(entity, model); }
@Test public void testConvertNullReturnsNull() { assertNull(converter.apply(null)); }