UserEditorDriver implements Driver<User, UserEditor> { public void edit(final User user, final UserEditor userEditor) { this.isFlushed = false; this.isEditMode = true; this.user = user; this.userEditor = userEditor; userEditor.edit(user); userEditor.attributesEditor().edit(user); userEditor.groupsExplorer().edit(user); userEditor.rolesExplorer().edit(user); } @Inject  UserEditorDriver(final ClientUserSystemManager userSystemManager); User createNewUser(final String identifier); void show(final User user,
                     final UserEditor userEditor); void edit(final User user,
                     final UserEditor userEditor); boolean flush(); @Override User getValue();  }
@Test public void testEdit() { final User user = mock(User.class); final UserEditor userEditor = mock(UserEditor.class); final UserAttributesEditor attributesEditor = mock(UserAttributesEditor.class); final UserAssignedGroupsExplorer groupsExplorer = mock(UserAssignedGroupsExplorer.class); final UserAssignedRolesExplorer rolesExplorer = mock(UserAssignedRolesExplorer.class); when(userEditor.attributesEditor()).thenReturn(attributesEditor); when(userEditor.groupsExplorer()).thenReturn(groupsExplorer); when(userEditor.rolesExplorer()).thenReturn(rolesExplorer); tested.isFlushed = true; tested.isEditMode = false; tested.edit(user, userEditor); assertEquals(user, tested.user); assertEquals(userEditor, tested.userEditor); assertFalse(tested.isFlushed); assertTrue(tested.isEditMode); verify(userEditor, times(1)).edit(user); verify(attributesEditor, times(1)).edit(user); verify(groupsExplorer, times(1)).edit(user); verify(rolesExplorer, times(1)).edit(user); verify(userEditor, times(0)).show(user); verify(attributesEditor, times(0)).show(user); verify(groupsExplorer, times(0)).show(user); verify(rolesExplorer, times(0)).show(user); verify(userEditor, times(0)).flush(); verify(attributesEditor, times(0)).flush(); verify(groupsExplorer, times(0)).flush(); verify(rolesExplorer, times(0)).flush(); }