Search in sources :

Example 1 with UsersTableModel

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)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 2 with UsersTableModel

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));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 3 with UsersTableModel

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)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 4 with UsersTableModel

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)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 5 with UsersTableModel

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)));
}
Also used : User(org.zaproxy.zap.users.User) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)49 UsersTableModel (org.zaproxy.zap.extension.users.UsersTableModel)49 ArrayList (java.util.ArrayList)15 User (org.zaproxy.zap.users.User)8 TableModelListener (javax.swing.event.TableModelListener)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1