### Question:
GrantStore extends AbstractStore<Grant> { public Grants getGrants(String did, String uid) throws StoreException { Grants grants = new Grants(); try (Connection conn = dbConnect(); PreparedStatement pstmt = conn .prepareStatement("SELECT * FROM grants WHERE domainid = ? AND userid = ?")) { pstmt.setString(1, did); pstmt.setString(2, uid); LOG.debug("query string: {}", pstmt); grants.setGrants(listFromStatement(pstmt)); } catch (SQLException e) { throw new StoreException("SQL Exception", e); } return grants; } GrantStore(ConnectionProvider dbConnectionFactory); Grants getGrants(String did, String uid); static final String SQL_ID; static final String SQL_TENANTID; static final String SQL_USERID; static final String SQL_ROLEID; }### Answer:
@Test public void getGrantsTest() throws 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, "GRANTS", tableTypes)).thenReturn(rsUserMock); Mockito.when(rsUserMock.next()).thenReturn(true); PreparedStatement pstmtMock = mock(PreparedStatement.class); Mockito.when(connectionMock.prepareStatement(anyString())).thenReturn(pstmtMock); ResultSet rsMock = getMockedResultSet(); Mockito.when(pstmtMock.executeQuery()).thenReturn(rsMock); Grants grants = grantStoreUnderTest.getGrants(did, uid); assertTrue(grants.getGrants().size() == 1); verify(pstmtMock).close(); }