@SuppressWarnings("unchecked") @Test void testDecorate() { String grandparentEntityTypeId = "grandparentEntityTypeId"; SystemEntityType grandparentEntityType = mock(SystemEntityType.class); when(grandparentEntityType.getId()).thenReturn(grandparentEntityTypeId); String parentEntityTypeId = "parentEntityTypeId"; SystemEntityType parentEntityType = mock(SystemEntityType.class); when(parentEntityType.getId()).thenReturn(parentEntityTypeId); when(parentEntityType.getExtends()).thenReturn(grandparentEntityType); String entityTypeId = "entityTypeId"; SystemEntityType entityType = mock(SystemEntityType.class); when(entityType.getId()).thenReturn(entityTypeId); when(entityType.getExtends()).thenReturn(parentEntityType); Repository<Entity> repository = mock(Repository.class); when(repository.getEntityType()).thenReturn(entityType); SystemRepositoryDecoratorFactory entityTypeFactory = mock(SystemRepositoryDecoratorFactory.class); when(entityTypeFactory.getEntityType()).thenReturn(entityType); systemRepositoryDecoratorRegistryImpl.addFactory(entityTypeFactory); SystemRepositoryDecoratorFactory grandparentEntityTypeFactory = mock(SystemRepositoryDecoratorFactory.class); when(grandparentEntityTypeFactory.getEntityType()).thenReturn(grandparentEntityType); systemRepositoryDecoratorRegistryImpl.addFactory(grandparentEntityTypeFactory); Repository<Entity> decoratedRepository = mock(Repository.class); when(grandparentEntityTypeFactory.createDecoratedRepository(repository)) .thenReturn(decoratedRepository); Repository decoratedDecoratedRepository = mock(Repository.class); when(entityTypeFactory.createDecoratedRepository(decoratedRepository)) .thenReturn(decoratedDecoratedRepository); assertEquals( decoratedDecoratedRepository, systemRepositoryDecoratorRegistryImpl.decorate(repository)); }
@SuppressWarnings("unchecked") @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { Repository<Entity> decoratedRepository = repository; for (String factoryId : getFactoryIds(repository)) { SystemRepositoryDecoratorFactory factory = factories.get(factoryId); if (factory != null) { decoratedRepository = factory.createDecoratedRepository(decoratedRepository); } } return decoratedRepository; }
SystemRepositoryDecoratorRegistryImpl implements SystemRepositoryDecoratorRegistry { @SuppressWarnings("unchecked") @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { Repository<Entity> decoratedRepository = repository; for (String factoryId : getFactoryIds(repository)) { SystemRepositoryDecoratorFactory factory = factories.get(factoryId); if (factory != null) { decoratedRepository = factory.createDecoratedRepository(decoratedRepository); } } return decoratedRepository; } }
SystemRepositoryDecoratorRegistryImpl implements SystemRepositoryDecoratorRegistry { @SuppressWarnings("unchecked") @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { Repository<Entity> decoratedRepository = repository; for (String factoryId : getFactoryIds(repository)) { SystemRepositoryDecoratorFactory factory = factories.get(factoryId); if (factory != null) { decoratedRepository = factory.createDecoratedRepository(decoratedRepository); } } return decoratedRepository; }  }
SystemRepositoryDecoratorRegistryImpl implements SystemRepositoryDecoratorRegistry { @SuppressWarnings("unchecked") @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { Repository<Entity> decoratedRepository = repository; for (String factoryId : getFactoryIds(repository)) { SystemRepositoryDecoratorFactory factory = factories.get(factoryId); if (factory != null) { decoratedRepository = factory.createDecoratedRepository(decoratedRepository); } } return decoratedRepository; }  @Override synchronized void addFactory(SystemRepositoryDecoratorFactory factory); @SuppressWarnings("unchecked") @Override synchronized Repository<Entity> decorate(Repository<Entity> repository); }
SystemRepositoryDecoratorRegistryImpl implements SystemRepositoryDecoratorRegistry { @SuppressWarnings("unchecked") @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { Repository<Entity> decoratedRepository = repository; for (String factoryId : getFactoryIds(repository)) { SystemRepositoryDecoratorFactory factory = factories.get(factoryId); if (factory != null) { decoratedRepository = factory.createDecoratedRepository(decoratedRepository); } } return decoratedRepository; }  @Override synchronized void addFactory(SystemRepositoryDecoratorFactory factory); @SuppressWarnings("unchecked") @Override synchronized Repository<Entity> decorate(Repository<Entity> repository);  }