@SuppressWarnings({"resource", "unchecked", "rawtypes"}) @Test void updateStreamWithListeners() { Repository<Entity> decoratedRepository = Mockito.mock(Repository.class); Mockito.when(decoratedRepository.getName()).thenReturn("entityFullName"); EntityListenerRepositoryDecorator entityListenerRepositoryDecorator = new EntityListenerRepositoryDecorator(decoratedRepository, entityListenersService); EntityListener entityListener0 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(1).getMock(); EntityListener entityListener1 = Mockito.when(Mockito.mock(EntityListener.class).getEntityId()).thenReturn(2).getMock(); entityListenersService.addEntityListener("entityFullName", entityListener0); entityListenersService.addEntityListener("entityFullName", entityListener1); Entity entity0 = Mockito.when(Mockito.mock(Entity.class).getIdValue()).thenReturn(1).getMock(); Entity entity1 = Mockito.when(Mockito.mock(Entity.class).getIdValue()).thenReturn(2).getMock(); Stream<Entity> entities = Stream.of(entity0, entity1); entityListenerRepositoryDecorator.update(entities); ArgumentCaptor<Stream<Entity>> captor = ArgumentCaptor.forClass(Stream.class); Mockito.verify(decoratedRepository).update(captor.capture()); assertEquals(asList(entity0, entity1), captor.getValue().collect(toList())); Mockito.verify(entityListener0, Mockito.times(1)).postUpdate(entity0); Mockito.verify(entityListener1, Mockito.times(1)).postUpdate(entity1); }
@Override public void update(Entity entity) { entityListenersService.updateEntity(delegate().getName(), entity); delegate().update(entity); }
EntityListenerRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void update(Entity entity) { entityListenersService.updateEntity(delegate().getName(), entity); delegate().update(entity); } }
EntityListenerRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void update(Entity entity) { entityListenersService.updateEntity(delegate().getName(), entity); delegate().update(entity); } EntityListenerRepositoryDecorator(
      Repository<Entity> delegateRepository, EntityListenersService entityListenersService); }
EntityListenerRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void update(Entity entity) { entityListenersService.updateEntity(delegate().getName(), entity); delegate().update(entity); } EntityListenerRepositoryDecorator(
      Repository<Entity> delegateRepository, EntityListenersService entityListenersService); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); }
EntityListenerRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void update(Entity entity) { entityListenersService.updateEntity(delegate().getName(), entity); delegate().update(entity); } EntityListenerRepositoryDecorator(
      Repository<Entity> delegateRepository, EntityListenersService entityListenersService); @Override void update(Entity entity); @Override void update(Stream<Entity> entities);  }