@SuppressWarnings("unchecked") @Test void addStream() { String password = "password"; User user0 = mock(User.class); when(user0.getPassword()).thenReturn(password); User user1 = mock(User.class); when(user1.getPassword()).thenReturn(password); when(delegateRepository.add(any(Stream.class))) .thenAnswer( invocation -> { Stream<Entity> entities = (Stream<Entity>) invocation.getArguments()[0]; List<Entity> entitiesList = entities.collect(toList()); return entitiesList.size(); }); assertEquals(valueOf(2), userRepositoryDecorator.add(of(user0, user1))); verify(passwordEncoder, times(2)).encode(password); }
@Override public void add(User entity) { encodePassword(entity); delegate().add(entity); }
UserRepositoryDecorator extends AbstractRepositoryDecorator<User> { @Override public void add(User entity) { encodePassword(entity); delegate().add(entity); } }
UserRepositoryDecorator extends AbstractRepositoryDecorator<User> { @Override public void add(User entity) { encodePassword(entity); delegate().add(entity); } UserRepositoryDecorator(Repository<User> delegateRepository, PasswordEncoder passwordEncoder); }
UserRepositoryDecorator extends AbstractRepositoryDecorator<User> { @Override public void add(User entity) { encodePassword(entity); delegate().add(entity); } UserRepositoryDecorator(Repository<User> delegateRepository, PasswordEncoder passwordEncoder); @Override void add(User entity); @Override void update(User entity); @Override Integer add(Stream<User> entities); @Override void update(Stream<User> entities); @Override void delete(User entity); @Override void delete(Stream<User> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); }
UserRepositoryDecorator extends AbstractRepositoryDecorator<User> { @Override public void add(User entity) { encodePassword(entity); delegate().add(entity); } UserRepositoryDecorator(Repository<User> delegateRepository, PasswordEncoder passwordEncoder); @Override void add(User entity); @Override void update(User entity); @Override Integer add(Stream<User> entities); @Override void update(Stream<User> entities); @Override void delete(User entity); @Override void delete(Stream<User> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll();  }