private Object assertQueryGeneratesSql(String query, String sql) {
   Sales sales = getSales();
   Connection oldConnection = sales.getConnection();
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   Connection newConnection = createTracingConnection(oldConnection, pw);
   sales.setConnection(newConnection);
   Object o;
   try {
     o = runQuery(query);
     pw.flush();
     String s = sw.toString();
     assertTrue(s, s.indexOf(sql) >= 0);
   } finally {
     sales.setConnection(oldConnection);
   }
   return o;
 }