use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectChangesToSelectedTableUser.
@Test
void shouldReflectChangesToSelectedTableUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
User user = copyUser(tableModel.getUsers().get(1));
// When
tableModel.modifyElement(1, user);
// Then
assertThat(usersListModel.getElementAt(1), is(equalTo((Object) user)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) user)));
assertThat(usersListModel.getSelectedItem(), is(sameInstance((Object) user)));
assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
assertThat(listener.isListItemChanged(1), is(equalTo(true)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectRemovedTableUserAndRemoveSelectionOfClearedUserToAvailableUser.
@Test
void shouldReflectRemovedTableUserAndRemoveSelectionOfClearedUserToAvailableUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
tableModel.removeElement(1);
// Then
assertThat(usersListModel.getSize(), is(equalTo(1)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
assertThat(listener.isListItemRemoved(1), is(equalTo(true)));
assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldGetIndexOfTableUsers.
@Test
void shouldGetIndexOfTableUsers() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
// When
int index = usersListModel.getIndexOf(tableModel.getUsers().get(1));
// Then
assertThat(index, is(equalTo(1)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectRemovedTableUserAndNotChangeSelectionIfNotTheSelectedUser.
@Test
void shouldReflectRemovedTableUserAndNotChangeSelectionIfNotTheSelectedUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
tableModel.removeElement(0);
// Then
assertThat(usersListModel.getSize(), is(equalTo(1)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
assertThat(listener.isListItemRemoved(0), is(equalTo(true)));
assertThat(listener.isListItemChanged(-1), is(equalTo(false)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectAddedTableUserAndNotSelectFirstTableUserIfOneAlreadySelected.
@Test
void shouldReflectAddedTableUserAndNotSelectFirstTableUserIfOneAlreadySelected() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(0));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
User user = createUser();
// When
tableModel.addElement(user);
// Then
assertThat(usersListModel.getSize(), is(equalTo(3)));
assertThat(usersListModel.getElementAt(2), is(equalTo((Object) user)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
assertThat(listener.isListItemAdded(2), is(equalTo(true)));
}
Aggregations