UidGenerator { public List<Event> assignUidToEvents(List<Event> events ) { for ( Event event : events ) { doAssignUid( event ); } return events; }  List<Event> assignUidToEvents(List<Event> events ); Event assignUidToEvent( Event event );  }
@Test public void verifyEventsGetUidAssigned() { final String uid = CodeGenerator.generateUid(); Event event1 = new Event(); Event event2 = new Event(); Event event3 = new Event(); Event event4 = new Event(); event4.setEvent( uid ); List<Event> events = subject.assignUidToEvents( Lists.newArrayList( event1, event2, event3, event4 ) ); assertThat( events, hasSize( 4 ) ); events.forEach( e -> assertNotNull( e.getUid() ) ); assertThat( events.stream().collect( Collectors.toMap( Event::getUid, Function.identity() ) ).keySet(), hasSize( 4 ) ); assertThat( event4.getUid(), is( uid ) ); assertThat( event4.getEvent(), is( uid ) ); }