### Question:
DomainStore extends AbstractStore<Domain> { public Domains getDomains() throws StoreException { Domains domains = new Domains(); domains.setDomains(listAll()); return domains; } DomainStore(final ConnectionProvider dbConnectionFactory); Domains getDomains(); Domain createDomain(final Domain domain); static final String SQL_ID; static final String SQL_NAME; static final String SQL_DESCR; static final String SQL_ENABLED; }### Answer:
@Test public void getDomainsTest() 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, "DOMAINS", 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); Domains domains = domainStoreUnderTest.getDomains(); assertTrue(domains.getDomains().size() == 1); verify(stmtMock).close(); }