Search in sources :

Example 41 with UsersTableModel

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

Example 42 with UsersTableModel

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

Example 43 with UsersTableModel

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

Example 44 with UsersTableModel

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

Example 45 with UsersTableModel

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)));
}
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