@Test void testGet() { EntityType entityType1 = mock(EntityType.class); EntityType entityType2 = mock(EntityType.class); EntityType entityType3 = mock(EntityType.class); Package package1 = mock(Package.class); Package package2 = mock(Package.class); ResourceIdentifier id1 = ResourceIdentifier.create(ResourceType.ENTITY_TYPE, "entity1"); ResourceIdentifier id2 = ResourceIdentifier.create(ResourceType.ENTITY_TYPE, "entity2"); ResourceIdentifier id3 = ResourceIdentifier.create(ResourceType.ENTITY_TYPE_ABSTRACT, "entity3"); ResourceIdentifier id4 = ResourceIdentifier.create(ResourceType.PACKAGE, "package1"); ResourceIdentifier id5 = ResourceIdentifier.create(ResourceType.PACKAGE, "package2"); when(metaDataService.getEntityType(any(String.class))) .thenAnswer( invocation -> { String id = invocation.getArgument(0); switch (id) { case "entity1": return Optional.of(entityType1); case "entity2": return Optional.of(entityType2); case "entity3": return Optional.of(entityType3); default: return null; } }); when(metaDataService.getPackage(any(String.class))) .thenAnswer( invocation -> { String id = invocation.getArgument(0); switch (id) { case "package1": return Optional.of(package1); case "package2": return Optional.of(package2); default: return null; } }); ResourceCollection collection = resourceCollector.get(asList(id1, id2, id3, id4, id5)); assertEquals(asList(entityType1, entityType2, entityType3), collection.getEntityTypes()); assertEquals(asList(package1, package2), collection.getPackages()); }
public ResourceCollection get(List<ResourceIdentifier> resources) { List<Package> packages = new ArrayList<>(); List<EntityType> entityTypes = new ArrayList<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packages.add(getPackage(resource.getId())); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypes.add(getEntityType(resource.getId())); break; default: throw new UnexpectedEnumException(resource.getType()); } }); return ResourceCollection.of(packages, entityTypes); }
ResourceCollector { public ResourceCollection get(List<ResourceIdentifier> resources) { List<Package> packages = new ArrayList<>(); List<EntityType> entityTypes = new ArrayList<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packages.add(getPackage(resource.getId())); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypes.add(getEntityType(resource.getId())); break; default: throw new UnexpectedEnumException(resource.getType()); } }); return ResourceCollection.of(packages, entityTypes); } }
ResourceCollector { public ResourceCollection get(List<ResourceIdentifier> resources) { List<Package> packages = new ArrayList<>(); List<EntityType> entityTypes = new ArrayList<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packages.add(getPackage(resource.getId())); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypes.add(getEntityType(resource.getId())); break; default: throw new UnexpectedEnumException(resource.getType()); } }); return ResourceCollection.of(packages, entityTypes); } ResourceCollector(MetaDataService metaDataService); }
ResourceCollector { public ResourceCollection get(List<ResourceIdentifier> resources) { List<Package> packages = new ArrayList<>(); List<EntityType> entityTypes = new ArrayList<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packages.add(getPackage(resource.getId())); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypes.add(getEntityType(resource.getId())); break; default: throw new UnexpectedEnumException(resource.getType()); } }); return ResourceCollection.of(packages, entityTypes); } ResourceCollector(MetaDataService metaDataService); ResourceCollection get(List<ResourceIdentifier> resources); }
ResourceCollector { public ResourceCollection get(List<ResourceIdentifier> resources) { List<Package> packages = new ArrayList<>(); List<EntityType> entityTypes = new ArrayList<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packages.add(getPackage(resource.getId())); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypes.add(getEntityType(resource.getId())); break; default: throw new UnexpectedEnumException(resource.getType()); } }); return ResourceCollection.of(packages, entityTypes); } ResourceCollector(MetaDataService metaDataService); ResourceCollection get(List<ResourceIdentifier> resources);  }