### Question:
FactTypeHelper { public void assertObjectTypesToBindExist(List<FactObjectBindingDefinition> bindingDefinitions, String propertyName) throws InvalidArgumentException { if (CollectionUtils.isEmpty(bindingDefinitions)) return; InvalidArgumentException ex = new InvalidArgumentException(); for (int i = 0; i < bindingDefinitions.size(); i++) { UUID sourceObjectType = bindingDefinitions.get(i).getSourceObjectType(); UUID destinationObjectType = bindingDefinitions.get(i).getDestinationObjectType(); if (sourceObjectType == null && destinationObjectType == null) { ex.addValidationError("Object binding definition must specify at least one of 'sourceObjectType' or 'destinationObjectType'.", "invalid.object.binding.definition", String.format("%s[%d]", propertyName, i), "NULL"); } if (sourceObjectType != null && objectManager.getObjectType(sourceObjectType) == null) { ex.addValidationError(String.format("ObjectType with id = %s does not exist.", sourceObjectType), "object.type.not.exist", String.format("%s[%d].sourceObjectType", propertyName, i), sourceObjectType.toString()); } if (destinationObjectType != null && objectManager.getObjectType(destinationObjectType) == null) { ex.addValidationError(String.format("ObjectType with id = %s does not exist.", destinationObjectType), "object.type.not.exist", String.format("%s[%d].destinationObjectType", propertyName, i), destinationObjectType.toString()); } } if (ex.hasErrors()) throw ex; } @Inject  FactTypeHelper(FactManager factManager, ObjectManager objectManager); void assertFactTypeNotExists(String name); void assertObjectTypesToBindExist(List<FactObjectBindingDefinition> bindingDefinitions, String propertyName); void assertFactTypesToBindExist(List<MetaFactBindingDefinition> bindingDefinitions, String propertyName); Set<FactTypeEntity.FactObjectBindingDefinition> convertFactObjectBindingDefinitions(List<FactObjectBindingDefinition> bindingDefinitions); Set<FactTypeEntity.MetaFactBindingDefinition> convertMetaFactBindingDefinitions(List<MetaFactBindingDefinition> bindingDefinitions);  }### Answer:
@Test public void testAssertObjectTypesToBindExistWithoutBindings() throws Exception { helper.assertObjectTypesToBindExist(null, "property"); helper.assertObjectTypesToBindExist(ListUtils.list(), "property"); verifyZeroInteractions(objectManager); }
@Test public void testAssertObjectTypesToBindSuccess() throws Exception { UUID sourceObjectType = UUID.randomUUID(); UUID destinationObjectType = UUID.randomUUID(); List<FactObjectBindingDefinition> definitions = ListUtils.list(new FactObjectBindingDefinition() .setSourceObjectType(sourceObjectType) .setDestinationObjectType(destinationObjectType) ); when(objectManager.getObjectType(isA(UUID.class))).thenReturn(new ObjectTypeEntity()); helper.assertObjectTypesToBindExist(definitions, "property"); verify(objectManager).getObjectType(sourceObjectType); verify(objectManager).getObjectType(destinationObjectType); }
@Test public void testAssertObjectTypesToBindExistWithoutSourceAndDestination() { List<FactObjectBindingDefinition> definitions = ListUtils.list(new FactObjectBindingDefinition()); try { helper.assertObjectTypesToBindExist(definitions, "property"); fail(); } catch (InvalidArgumentException ignored) { } verifyZeroInteractions(objectManager); }
@Test public void testAssertObjectTypesToBindExistFailsOnSource() { UUID sourceObjectType = UUID.randomUUID(); List<FactObjectBindingDefinition> definitions = ListUtils.list(new FactObjectBindingDefinition() .setSourceObjectType(sourceObjectType) ); try { helper.assertObjectTypesToBindExist(definitions, "property"); fail(); } catch (InvalidArgumentException ignored) { } verify(objectManager).getObjectType(sourceObjectType); }
@Test public void testAssertObjectTypesToBindExistFailsOnDestination() { UUID destinationObjectType = UUID.randomUUID(); List<FactObjectBindingDefinition> definitions = ListUtils.list(new FactObjectBindingDefinition() .setDestinationObjectType(destinationObjectType) ); try { helper.assertObjectTypesToBindExist(definitions, "property"); fail(); } catch (InvalidArgumentException ignored) { } verify(objectManager).getObjectType(destinationObjectType); }