Ejemplo n.º 1
0
  @Test
  public void getRolesTest() throws SQLException, Exception {
    // Setup Mock Behavior
    String[] tableTypes = {"TABLE"};
    Mockito.when(connectionMock.isClosed()).thenReturn(false);
    DatabaseMetaData dbmMock = mock(DatabaseMetaData.class);
    Mockito.when(connectionMock.getMetaData()).thenReturn(dbmMock);
    ResultSet rsUserMock = mock(ResultSet.class);
    Mockito.when(dbmMock.getTables(null, null, "ROLES", tableTypes)).thenReturn(rsUserMock);
    Mockito.when(rsUserMock.next()).thenReturn(true);

    Statement stmtMock = mock(Statement.class);
    Mockito.when(connectionMock.createStatement()).thenReturn(stmtMock);

    ResultSet rsMock = getMockedResultSet();
    Mockito.when(stmtMock.executeQuery(anyString())).thenReturn(rsMock);

    // Run Test
    Roles roles = RoleStoreUnderTest.getRoles();

    // Verify
    assertTrue(roles.getRoles().size() == 1);
    verify(stmtMock).close();
  }
Ejemplo n.º 2
0
 @Before
 public void setup() {
   RoleStoreUnderTest.dbConnection = connectionMock;
 }