### Question:
JdbcNeo4JReader extends JdbcReader implements IJdbcReader { @Override public void init(Partition p) throws Exception { Class.forName(Driver.class.getCanonicalName()); conn = DriverManager.getConnection(jdbcNeo4JDeepJobConfig.getConnectionUrl(), jdbcNeo4JDeepJobConfig.getUsername(), jdbcNeo4JDeepJobConfig.getPassword()); Statement statement = conn.createStatement(); String query = jdbcNeo4JDeepJobConfig.getCypherQuery(); resultSet = statement.executeQuery(query); this.hasNext = resultSet.next(); } JdbcNeo4JReader(JdbcNeo4JDeepJobConfig config); @Override void init(Partition p);  }### Answer:
@Test public void testNextRowOnInitWhenResultSetIsEmpty() throws Exception { PowerMockito.mockStatic(DriverManager.class); when(config.getConnectionUrl()).thenReturn(WHATEVER_CONSTANT); when(config.getUsername()).thenReturn(WHATEVER_CONSTANT); when(config.getPassword()).thenReturn(WHATEVER_CONSTANT); when(config.getQuery()).thenReturn(mock(SelectQuery.class)); when(DriverManager.getConnection(anyString(), anyString(), anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(statement); when(statement.executeQuery(anyString())).thenReturn(resultSet); when(resultSet.next()).thenReturn(false); JdbcNeo4JReader reader = new JdbcNeo4JReader(config); reader.init(partition); Class<?> clazz = JdbcNeo4JReader.class; Field hasNextField = clazz.getSuperclass().getDeclaredField("hasNext"); hasNextField.setAccessible(true); assertEquals(hasNextField.get(reader), false, "hasNext field should be set to FALSE"); }
@Test public void testNextRowOnInitWhenResultSetIsNotEmpty() throws Exception { PowerMockito.mockStatic(DriverManager.class); when(config.getConnectionUrl()).thenReturn(WHATEVER_CONSTANT); when(config.getUsername()).thenReturn(WHATEVER_CONSTANT); when(config.getPassword()).thenReturn(WHATEVER_CONSTANT); when(config.getQuery()).thenReturn(mock(SelectQuery.class)); when(DriverManager.getConnection(anyString(), anyString(), anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(statement); when(statement.executeQuery(anyString())).thenReturn(resultSet); when(resultSet.next()).thenReturn(true); JdbcNeo4JReader reader = new JdbcNeo4JReader(config); reader.init(partition); Class<?> clazz = JdbcNeo4JReader.class; Field hasNextField = clazz.getSuperclass().getDeclaredField("hasNext"); hasNextField.setAccessible(true); assertEquals(hasNextField.get(reader), true, "hasNext field should be set to TRUE"); }