### Question:
RoleStore extends AbstractStore<Role> { public Roles getRoles() throws StoreException { Roles roles = new Roles(); roles.setRoles(listAll()); return roles; } RoleStore(final ConnectionProvider dbConnectionFactory); Roles getRoles(); static final String SQL_ID; static final String SQL_NAME; static final String SQL_DESCR; }### Answer:
@Test public void getRolesTest() throws SQLException, Exception { 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); Roles roles = roleStoreUnderTest.getRoles(); assertTrue(roles.getRoles().size() == 1); verify(stmtMock).close(); }