SortedUserList implements UserList { @Override public User set(final int pos, final User user) { Validate.notNull(user, "User can not be null"); final User oldUser = userList.set(pos, user); Collections.sort(userList); fireUserChanged(userList.indexOf(user), user); return oldUser; } 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 setShouldThrowExceptionIfUserIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("User can not be null"); userList.set(0, null); }
@Test public void setShouldNotifyListenersAboutTheNewPosition() { addAllUsers(); final User test1 = new User("Test1", 10); userList.set(0, test1); verify(listener).userChanged(3, test1); }
@Test public void setShouldFailIfTryingToReplaceUserThatDoesNotExist() { expectedException.expect(IndexOutOfBoundsException.class); userList.set(0, new User("Test1", 10)); }