Ejemplo n.º 1
0
  public void assertResultSetOrderAgnostic(
      final ResultSet resultSet, final List<DBQueries.Row<Integer, String>> rows) {

    try {
      List<DBQueries.Row<Integer, String>> actual =
          new ArrayList<DBQueries.Row<Integer, String>>(rows.size());
      while (resultSet.next()) {
        actual.add(new DBQueries.Row<Integer, String>(resultSet.getInt(1), resultSet.getString(2)));
      }

      Comparator<DBQueries.Row<Integer, String>> comparator =
          new Comparator<DBQueries.Row<Integer, String>>() {
            @Override
            public int compare(
                DBQueries.Row<Integer, String> o1, DBQueries.Row<Integer, String> o2) {
              int objectKeyComparison = o1.getObjectKey().compareTo(o2.getObjectKey());
              if (objectKeyComparison != 0) {
                return objectKeyComparison;
              }
              return o1.getValue().compareTo(o2.getValue());
            }
          };

      Collections.sort(actual, comparator);
      Collections.sort(rows, comparator);

      Assert.assertEquals(rows, actual);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to verify resultSet", e);
    }
  }
Ejemplo n.º 2
0
  public void assertResultSetObjectKeysOrderAgnostic(
      final ResultSet resultSet, final List<Integer> objectKeys) {
    try {
      List<Integer> actual = new ArrayList<Integer>(objectKeys.size());
      while (resultSet.next()) {
        actual.add(resultSet.getInt(1));
      }

      Collections.sort(actual);
      Collections.sort(objectKeys);

      Assert.assertEquals(objectKeys, actual);

    } catch (Exception e) {
      throw new IllegalStateException("Unable to verify resultSet", e);
    }
  }