use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldSetSelectedItemUser.
@Test
void shouldSetSelectedItemUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
usersListModel.setSelectedItem(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 shouldHaveNoEffectReselectSameUser.
@Test
void shouldHaveNoEffectReselectSameUser() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
// Then
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(1))));
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 shouldSetSelectedItemUserEvenIfOneWasPreviouslySelected.
@Test
void shouldSetSelectedItemUserEvenIfOneWasPreviouslySelected() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(1));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
usersListModel.setSelectedItem(tableModel.getUsers().get(0));
// Then
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
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 shouldReflectChangesToTableUsersAndNotSelectFirstTableUserIfOneAlreadySelected.
@Test
void shouldReflectChangesToTableUsersAndNotSelectFirstTableUserIfOneAlreadySelected() {
// Given
UsersTableModel tableModel = createUsersTableModel(3);
UsersListModel usersListModel = new UsersListModel(tableModel);
usersListModel.setSelectedItem(tableModel.getUsers().get(2));
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
User user = createUser();
// When
tableModel.modifyElement(1, user);
// Then
assertThat(usersListModel.getElementAt(1), is(equalTo((Object) user)));
assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(2))));
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 shouldReflectClearedTableUsersAndNotChangeSelectionIfNoUserSelectedNorAvailable.
@Test
void shouldReflectClearedTableUsersAndNotChangeSelectionIfNoUserSelectedNorAvailable() {
// Given
UsersTableModel tableModel = createUsersTableModel(2);
UsersListModel usersListModel = new UsersListModel(tableModel);
TestListDataListener listener = createTestListDataListener();
usersListModel.addListDataListener(listener);
// When
tableModel.clear();
// Then
assertThat(usersListModel.getSize(), is(equalTo(0)));
assertThat(usersListModel.getSelectedItem(), is(nullValue()));
assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
assertThat(listener.isListItemChanged(0), is(equalTo(true)));
assertThat(listener.isListItemChanged(1), is(equalTo(true)));
assertThat(listener.isListItemChanged(-1), is(equalTo(false)));
}
Aggregations