RelationshipResolver { public List<Entity> removeUnresolvedEntities(Set<Entity> entities) { List<Entity> resolvedEntities = new ArrayList<>(); EntitiesRetriever entitiesRetriever = new EntitiesRetriever(entities); for (Entity entity : entities) { if (isEntityResolved(entity, new ArrayList<>(), new ArrayList<>(), entitiesRetriever)) { resolvedEntities.add(entity); } } return resolvedEntities; }  List<Entity> removeUnresolvedEntities(Set<Entity> entities); @Autowired void setAllEntities(AllEntities allEntities);  }
@Test public void shouldRemoveUnresolvedEntitiesForSimpleTopology() { setupSimpleTopology(); assertEntities(asSet(entityC), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityB, entityC))); assertEntities(asSet(entityC, entityD), relationshipResolver.removeUnresolvedEntities(asSet(entityD, entityA, entityC))); }
@Test public void shouldNotRemoveResolvedEntitiesForSimpleTopology() { setupSimpleTopology(); assertEntities(asSet(entityB, entityC, entityD), relationshipResolver.removeUnresolvedEntities(asSet(entityD, entityB, entityC))); assertEntities(asSet(entityA, entityB, entityC, entityD), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityD, entityB, entityC))); }
@Test public void shouldRemoveUnresolvedEntitiesForComplexTopology() { setupComplexTopology(); assertEntities(asSet(entityD, entityE), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityB, entityC, entityD, entityE))); assertEntities(asSet(entityD, entityE, entityF), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityB, entityD, entityE, entityF))); assertEntities(asSet(entityC, entityD, entityE, entityF), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityC, entityD, entityE, entityF))); }
@Test public void shouldNotRemoveResolvedEntitiesForComplexTopology() { setupComplexTopology(); assertEntities(asSet(entityA, entityB, entityC, entityD, entityE, entityF), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityB, entityC, entityD, entityE, entityF))); }
@Test public void shouldRemoveUnresolvedEntitiesForComplexTopologyWithLoop() { setupComplexTopologyWithLoop(); assertEntities(asSet(entityF), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityB, entityC, entityD, entityF))); assertEntities(this.<Entity>asSet(), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityC, entityE, entityD))); assertEntities(this.<Entity>asSet(), relationshipResolver.removeUnresolvedEntities(asSet(entityA, entityC, entityD, entityE, entityB))); }
@Test public void shouldNotRemoveResolvedEntitiesForComplexTopologyWithLoop() { setupComplexTopologyWithLoop(); assertEntities(asSet(entityA, entityB, entityC, entityD, entityE, entityF), relationshipResolver.removeUnresolvedEntities(asSet(entityE, entityB, entityF, entityD, entityA, entityC))); }