OrmFactoryRegistryImpl implements OrmFactoryRegistry { @Override @SuppressWarnings("unchecked") public <T extends Thing> Optional<OrmFactory<T>> getFactoryOfType(Class<T> type) { return factories.stream() .filter(factory -> type.equals(factory.getType())) .map(factory -> (OrmFactory<T>) factory) .findFirst(); }  @Override @SuppressWarnings("unchecked") Optional<OrmFactory<T>> getFactoryOfType(Class<T> type); @Override Optional<OrmFactory<? extends Thing>> getFactoryOfType(String typeIRI); @Override Optional<OrmFactory<? extends Thing>> getFactoryOfType(IRI typeIRI); @Override List<OrmFactory<? extends T>> getFactoriesOfType(Class<T> type); @Override List<OrmFactory<? extends T>> getSortedFactoriesOfType(Class<T> type); @Override List<OrmFactory<? extends Thing>> getFactoriesOfType(String typeIRI); @Override List<OrmFactory<? extends Thing>> getSortedFactoriesOfType(String typeIRI); @Override List<OrmFactory<? extends Thing>> getFactoriesOfType(IRI typeIRI); @Override List<OrmFactory<? extends Thing>> getSortedFactoriesOfType(IRI typeIRI); @Override T createNew(Resource resource, Model model, Class<T> type); @Override Optional<T> getExisting(Resource resource, Model model, Class<T> type); @Override Collection<T> getAllExisting(Model model, Class<T> type); @Override void processAllExisting(Model model, Consumer<T> consumer, Class<T> type);  }
@Test public void getFactoryByTypeClassTest() throws Exception { Optional<OrmFactory<Thing>> result = registry.getFactoryOfType(Thing.class); assertTrue(result.isPresent()); assertEquals(thingFactory, result.get()); Optional<OrmFactory<A>> result2 = registry.getFactoryOfType(A.class); assertTrue(result2.isPresent()); assertEquals(aFactory, result2.get()); Optional<OrmFactory<B>> result3 = registry.getFactoryOfType(B.class); assertTrue(result3.isPresent()); assertEquals(bFactory, result3.get()); Optional<OrmFactory<C>> result4 = registry.getFactoryOfType(C.class); assertTrue(result4.isPresent()); assertEquals(cFactory, result4.get()); }
@Test public void getFactoryByTypeClassThatDoesNotExistTest() { assertFalse(registry.getFactoryOfType(Error.class).isPresent()); }
@Test public void getFactoryByTypeStringTest() throws Exception { Optional<OrmFactory<? extends Thing>> result = registry.getFactoryOfType(Thing.TYPE); assertTrue(result.isPresent()); assertEquals(thingFactory, result.get()); Optional<OrmFactory<? extends Thing>> result2 = registry.getFactoryOfType(A.TYPE); assertTrue(result2.isPresent()); assertEquals(aFactory, result2.get()); Optional<OrmFactory<? extends Thing>> result3 = registry.getFactoryOfType(B.TYPE); assertTrue(result3.isPresent()); assertEquals(bFactory, result3.get()); Optional<OrmFactory<? extends Thing>> result4 = registry.getFactoryOfType(C.TYPE); assertTrue(result4.isPresent()); assertEquals(cFactory, result4.get()); }
@Test public void getFactoryByTypeStringThatDoesNotExistTest() { assertFalse(registry.getFactoryOfType(Error.TYPE).isPresent()); }
@Test public void getFactoryByTypeIriTest() throws Exception { Optional<OrmFactory<? extends Thing>> result = registry.getFactoryOfType(thingIRI); assertTrue(result.isPresent()); assertEquals(thingFactory, result.get()); Optional<OrmFactory<? extends Thing>> result2 = registry.getFactoryOfType(aIRI); assertTrue(result2.isPresent()); assertEquals(aFactory, result2.get()); Optional<OrmFactory<? extends Thing>> result3 = registry.getFactoryOfType(bIRI); assertTrue(result3.isPresent()); assertEquals(bFactory, result3.get()); Optional<OrmFactory<? extends Thing>> result4 = registry.getFactoryOfType(cIRI); assertTrue(result4.isPresent()); assertEquals(cFactory, result4.get()); }
@Test public void getFactoryByTypeIriThatDoesNotExistTest() { assertFalse(registry.getFactoryOfType(errorIRI).isPresent()); }