コード例 #1
0
 @BeforeClass
 public static void setup() {
   try {
     Class.forName(INMEM_DB_DRIVER).newInstance();
     Connection con = DriverManager.getConnection(INMEM_DB_URL, new Properties());
     Statement stmt = con.createStatement();
     stmt.execute(
         "CREATE TABLE IF NOT EXISTS "
             + TABLE_NAME
             + " (col1 INTEGER, col2 INTEGER, col3 BIGINT)");
   } catch (InstantiationException e) {
     throw new RuntimeException(e);
   } catch (IllegalAccessException e) {
     throw new RuntimeException(e);
   } catch (ClassNotFoundException e) {
     throw new RuntimeException(e);
   } catch (SQLException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #2
0
    @Override
    public void endWindow() {
      try {
        Class.forName(INMEM_DB_DRIVER).newInstance();
        Connection con = DriverManager.getConnection(INMEM_DB_URL, new Properties());
        Statement stmt = con.createStatement();
        ResultSet resultSet =
            stmt.executeQuery("SELECT col2 FROM " + TABLE_NAME + " WHERE col1 = 1");
        ArrayList<Integer> answersOne = new ArrayList<Integer>();
        for (int i = 1; i < 16; i++) {
          answersOne.add(i);
        }
        Assert.assertEquals(answersOne, processResult(resultSet));

        resultSet = stmt.executeQuery("SELECT col2 FROM " + TABLE_NAME + " WHERE col1 = 2");
        ArrayList<Integer> answersTwo = new ArrayList<Integer>();
        answersTwo.add(3);
        answersTwo.add(6);
        answersTwo.add(9);
        for (int i = 11; i < 21; i++) {
          answersTwo.add(i);
        }
        Assert.assertEquals(answersTwo, processResult(resultSet));

        resultSet = stmt.executeQuery("SELECT col2 FROM " + TABLE_NAME + " WHERE col1 = 3");
        ArrayList<Integer> answersThree = new ArrayList<Integer>();
        answersThree.add(2);
        answersThree.add(4);
        answersThree.add(6);
        answersThree.add(8);
        answersThree.add(10);
        for (int i = 11; i < 21; i++) {
          answersThree.add(i);
        }
        Assert.assertEquals(answersThree, processResult(resultSet));
      } catch (Throwable e) {
        throw new RuntimeException(e);
      }
    }