SortedUserList implements UserList { @Override public int indexOf(final User user) { Validate.notNull(user, "User can not be null"); return userList.indexOf(user); } 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 indexOfShouldThrowExceptionIfUserIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("User can not be null"); userList.indexOf(null); }
@Test public void indexOfShouldReturnCorrectIndexOfUserInList() { addAllUsers(); assertEquals(0, userList.indexOf(annie)); assertEquals(1, userList.indexOf(john)); assertEquals(2, userList.indexOf(lenny)); assertEquals(3, userList.indexOf(niles)); }
@Test public void indexOfShouldReturnMinusOneIfUserDoesNotExist() { assertEquals(-1, userList.indexOf(annie)); }