Search in sources :

Example 46 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldReflectChangesToTableUsersAndSelectFirstTableUserIfNoneSelected.

@Test
void shouldReflectChangesToTableUsersAndSelectFirstTableUserIfNoneSelected() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    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(0))));
    assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
    assertThat(listener.isListItemChanged(1), 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)

Example 47 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldRemoveSelectionWithSelectedItem.

@Test
void shouldRemoveSelectionWithSelectedItem() {
    // 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(null);
    // Then
    assertThat(usersListModel.getSelectedItem(), is(nullValue()));
    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 48 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersTableModelUnitTest method shouldAddUser.

@Test
void shouldAddUser() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    UsersTableModel usersTableModel = new UsersTableModel();
    usersTableModel.addTableModelListener(listener);
    User user = createUser();
    // When
    usersTableModel.addUser(user);
    // Then
    assertThat(usersTableModel.getRowCount(), is(equalTo(1)));
    assertThat(usersTableModel.getUsers().size(), is(equalTo(1)));
    assertThat(usersTableModel.getUsers().get(0), is(equalTo(user)));
    assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isRowInserted(0), is(equalTo(true)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 49 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersTableModelUnitTest method shouldNotHaveUsersByDefault.

@Test
void shouldNotHaveUsersByDefault() {
    // Given
    UsersTableModel usersTableModel = new UsersTableModel();
    // When / Then
    assertThat(usersTableModel.getRowCount(), is(equalTo(0)));
    assertThat(usersTableModel.getUsers(), is(empty()));
    assertThat(usersTableModel.getElements(), is(empty()));
}
Also used : 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