use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectRemovedTableUserAndNotChangeSelectionIfNoUserSelectedNorAvailable.
@Test
void shouldReflectRemovedTableUserAndNotChangeSelectionIfNoUserSelectedNorAvailable() {
// Given
UsersTableModel tableModel = createUsersTableModel(1);
UsersListModel usersListModel = new UsersListModel(tableModel);
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
tableModel.removeElement(0);
// Then
assertThat(usersListModel.getSize(), is(equalTo(0)));
assertThat(usersListModel.getSelectedItem(), is(nullValue()));
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 shouldFailToCreateInstanceWithUndefinedUsersTableModel.
@Test
void shouldFailToCreateInstanceWithUndefinedUsersTableModel() {
// Given
UsersTableModel undefinedTableModel = null;
// When / Then
assertThrows(NullPointerException.class, () -> new UsersListModel(undefinedTableModel));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldHaveNoEffectRemoveSelectionIfNoSelectedUser.
@Test
void shouldHaveNoEffectRemoveSelectionIfNoSelectedUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
usersListModel.setSelectedItem(null);
// Then
assertThat(usersListModel.getSelectedItem(), is(nullValue()));
assertThat(listener.getNumberOfEvents(), is(equalTo(0)));
assertThat(listener.isListItemChanged(-1), is(equalTo(false)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldSetSelectedInternalTableUsers.
@Test
void shouldSetSelectedInternalTableUsers() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
usersListModel.setSelectedInternalItem(copyUser(tableModel.getUsers().get(1)));
// Then
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(1))));
assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldReflectRemovedTableUserAndSelectFirstCustomUser.
@Test
void shouldReflectRemovedTableUserAndSelectFirstCustomUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(1);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(0));
User customUser = createUser();
usersListModel.setCustomUsers(new User[] { customUser, createUser() });
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
tableModel.removeElement(0);
// Then
assertThat(usersListModel.getSize(), is(equalTo(2)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) customUser)));
assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
assertThat(listener.isListItemRemoved(0), is(equalTo(true)));
assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
Aggregations