Search in sources :

Example 11 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldChangeUsersEnabledState.

@Test
void shouldChangeUsersEnabledState() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createEnabledUser());
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.setValueAt(true, 0, 0);
    usersTableModel.setValueAt(false, 1, 0);
    // Then
    assertThat(usersTableModel.getValueAt(0, 0), is(equalTo((Object) true)));
    assertThat(usersTableModel.getValueAt(1, 0), is(equalTo((Object) false)));
    assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
    assertThat(listener.isCellChanged(0, 0), is(equalTo(true)));
    assertThat(listener.isCellChanged(1, 0), is(equalTo(true)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 12 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldNotNotifyOfEnabledStateChangesIfItHasNoUsers.

@Test
void shouldNotNotifyOfEnabledStateChangesIfItHasNoUsers() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    UsersTableModel usersTableModel = new UsersTableModel();
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.setAllEnabled(true);
    // Then
    assertThat(listener.getNumberOfEvents(), is(equalTo(0)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 13 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldReturnUserNameFromThirdColumn.

@Test
void shouldReturnUserNameFromThirdColumn() {
    // Given
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser("User 1"));
    usersList.add(createUser("User 2"));
    // When
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    // Then
    assertTrue(usersTableModel.getColumnClass(2) == String.class);
    assertThat(usersTableModel.getValueAt(0, 2), is(equalTo((Object) "User 1")));
    assertThat(usersTableModel.getValueAt(1, 2), is(equalTo((Object) "User 2")));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 14 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldFailToCreateInstanceWithUndefinedUsersList.

@Test
void shouldFailToCreateInstanceWithUndefinedUsersList() {
    // Given
    List<User> undefinedUsersList = null;
    // When / Then
    assertThrows(NullPointerException.class, () -> new UsersTableModel(undefinedUsersList));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 15 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldClearElements.

@Test
void shouldClearElements() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createEnabledUser());
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.clear();
    // Then
    assertThat(usersTableModel.getRowCount(), is(equalTo(0)));
    assertThat(usersTableModel.getElements(), is(empty()));
    assertThat(usersTableModel.getUsers(), is(empty()));
    assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isDataChanged(), is(equalTo(true)));
}
Also used : ArrayList(java.util.ArrayList) 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