@SuppressWarnings("unchecked") @Test void testUpdateStream() { Package existingGroupPackage = mockGroupPackage("group"); Package newGroupPackage = mockGroupPackage("group"); Package existingNonGroupPackage = mockNonGroupPackage("nonGroup"); Package newNonGroupPackage = mockNonGroupPackage("nonGroup"); Package existingUpdateToGroupPackage = mockNonGroupPackage("updateToGroup"); Package newUpdateToGroupPackage = mockGroupPackage("updateToGroup"); when(delegateRepository.findAll(any(Stream.class))) .thenReturn( Stream.of(existingGroupPackage, existingNonGroupPackage, existingUpdateToGroupPackage)); Stream<Package> packages = Stream.of(newGroupPackage, newNonGroupPackage, newUpdateToGroupPackage); groupPackageRepositoryDecorator.update(packages); ArgumentCaptor<Stream<Package>> streamCaptor = ArgumentCaptor.forClass(Stream.class); assertAll( () -> verify(delegateRepository).update(streamCaptor.capture()), () -> assertEquals( asList(newGroupPackage, newNonGroupPackage, newUpdateToGroupPackage), streamCaptor.getValue().collect(Collectors.toList())), () -> verify(groupPackageService).createGroup(newUpdateToGroupPackage), () -> verifyNoMoreInteractions(groupPackageService)); }
@Override public void update(Package aPackage) { Package currentPackage = getPackage(aPackage.getId()); validateUpdate(currentPackage, aPackage); super.update(aPackage); if (!isGroupPackage(currentPackage) && isGroupPackage(aPackage)) { groupPackageService.createGroup(aPackage); } }
GroupPackageRepositoryDecorator extends AbstractRepositoryDecorator<Package> { @Override public void update(Package aPackage) { Package currentPackage = getPackage(aPackage.getId()); validateUpdate(currentPackage, aPackage); super.update(aPackage); if (!isGroupPackage(currentPackage) && isGroupPackage(aPackage)) { groupPackageService.createGroup(aPackage); } } }
GroupPackageRepositoryDecorator extends AbstractRepositoryDecorator<Package> { @Override public void update(Package aPackage) { Package currentPackage = getPackage(aPackage.getId()); validateUpdate(currentPackage, aPackage); super.update(aPackage); if (!isGroupPackage(currentPackage) && isGroupPackage(aPackage)) { groupPackageService.createGroup(aPackage); } } GroupPackageRepositoryDecorator(
      Repository<Package> delegateRepository, GroupPackageService groupPackageService); }
GroupPackageRepositoryDecorator extends AbstractRepositoryDecorator<Package> { @Override public void update(Package aPackage) { Package currentPackage = getPackage(aPackage.getId()); validateUpdate(currentPackage, aPackage); super.update(aPackage); if (!isGroupPackage(currentPackage) && isGroupPackage(aPackage)) { groupPackageService.createGroup(aPackage); } } GroupPackageRepositoryDecorator(
      Repository<Package> delegateRepository, GroupPackageService groupPackageService); @Override void add(Package aPackage); @Override Integer add(Stream<Package> packageStream); @Override void update(Package aPackage); @Override void update(Stream<Package> packageStream); @Override void delete(Package aPackage); @Override void deleteById(Object id); @Override void deleteAll(); @Override void delete(Stream<Package> packages); @Override void deleteAll(Stream<Object> ids); }
GroupPackageRepositoryDecorator extends AbstractRepositoryDecorator<Package> { @Override public void update(Package aPackage) { Package currentPackage = getPackage(aPackage.getId()); validateUpdate(currentPackage, aPackage); super.update(aPackage); if (!isGroupPackage(currentPackage) && isGroupPackage(aPackage)) { groupPackageService.createGroup(aPackage); } } GroupPackageRepositoryDecorator(
      Repository<Package> delegateRepository, GroupPackageService groupPackageService); @Override void add(Package aPackage); @Override Integer add(Stream<Package> packageStream); @Override void update(Package aPackage); @Override void update(Stream<Package> packageStream); @Override void delete(Package aPackage); @Override void deleteById(Object id); @Override void deleteAll(); @Override void delete(Stream<Package> packages); @Override void deleteAll(Stream<Object> ids);  }