private void checkQueryPlan(Connection conn,String sql,String search) throws SQLException {
  try (Statement s=conn.createStatement()){
    try (ResultSet r=s.executeQuery("EXPLAIN ANALYZE " + sql)){
      assertTrue(r.next());
      String plan=r.getString(1);
      assertTrue("Execution plan for '" + sql + "' query should contain '"+ search+ "'",plan.contains(search));
    }
   }
 }

private void checkQueryPlan ( Connection conn , String sql , String search ) throws SQLException { try ( Statement s = conn . createStatement ( ) ) { try ( ResultSet r = s . executeQuery ( "EXPLAIN ANALYZE " + sql ) ) { assertTrue ( r . next ( ) ) ; String plan = r . getString ( 1 ) ; assertTrue ( "Execution plan for '" + sql + "' query should contain '" + search + "'" , plan . contains ( search ) ) ; } } }
check query plan to correctly select index .
