SortedUserList implements UserList { @Override public boolean remove(final User user) { Validate.notNull(user, "User can not be null"); final int pos = userList.indexOf(user); final boolean success = userList.remove(user); if (success) { fireUserRemoved(pos, user); } return success; } SortedUserList(); @Override boolean add(final User user); @Nullable @Override User get(final int pos); @Override int indexOf(final User user); @Override boolean remove(final User user); @Override User set(final int pos, final User user); @Override int size(); @Override void addUserListListener(final UserListListener listener); @Override void removeUserListListener(final UserListListener listener); List<UserListListener> getListeners();  }
@Test public void removeShouldThrowExceptionIfUserIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("User can not be null"); userList.remove(null); }
@Test public void removeShouldNotifyListeners() { addAllUsers(); userList.remove(john); verify(listener).userRemoved(1, john); }
@Test public void removeShouldReturnFalseIfUserDoesNotExist() { assertFalse(userList.remove(annie)); }
@Test public void removeShouldNotNotifyListenersIfUserDoesNotExist() { userList.remove(annie); verifyZeroInteractions(listener); }