@RunWith(PowerMockRunner.class)
@PrepareForTest(ConnectionPool.class)
public class TestClass {
private FactoryDAO factoryDAO = FactoryDAO.getInstance();
@Test
public void testaddAccount() throws SQLException {
String currUserEmail = "mail";
String account = "account";
String info = "info";
PreparedStatement statementMock = mock(PreparedStatement.class);
Connection connectionMock = mock(Connection.class);
ConnectionPool connectionPoolMock = mock(ConnectionPool.class);
when(connectionPoolMock.getConnection()).thenReturn(statementMock);
when(connectionMock.prepareStatement(SQL_ADD_CARD)).thenReturn(statementMock);
mockStatic(ConnectionPool.class);
expect(ConnectionPool.getInstance()).andReturn(connectionPoolMock);
assertEquals(true, factoryDAO.getAccountDao().addAccount(currUserEmail, account, info));
verify(statementMock).setString(1, currUserEmail);
verify(statementMock).setString(2, account);
verify(statementMock).setString(3, info);
}
}
asterisk -vvvgc
agi set debug on
Одним запросом будет дороже, чем подзапросом