/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.cloud.bigquery.dwhassessment.extractiontool.faketd;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TeradataSimulatorTest {

  private static final String FAKE_TERADATA_URL = "jdbc:hsqldb:mem:faketd";

  @Test
  public void populate_success() throws SQLException, IOException {
    try (Connection connection = getFakeTeradataConnection()) {
      try (Statement statement = connection.createStatement()) {
        ResultSet rs = statement.executeQuery(
            "SELECT" +
                "  DatabaseName," +
                "  TableName," +
                "  LastAccessTimeStamp AT TIME ZONE INTERVAL '0:00' HOUR TO MINUTE " +
                "FROM DBC.TablesV");
        while (rs.next()) {
          System.out.printf("DB: %s, table: %s%n", rs.getString("DatabaseName"),
              rs.getString("TableName"));
        }
      }
    }
  }

  private static Connection getFakeTeradataConnection() throws SQLException, IOException {
    TeradataSimulator.populate(FAKE_TERADATA_URL);
    return DriverManager.getConnection(FAKE_TERADATA_URL);
  }
}

@@ -660,16 +660,73 @@
 aketd;%0A%0A
+import static com.google.common.truth.Truth.assertThat;%0A%0A
 import j
@@ -1329,16 +1329,21 @@
         
+try (
 ResultSe
@@ -1348,16 +1348,28 @@
 Set rs =
+%0A           
  stateme
@@ -1401,16 +1401,20 @@
     
+    
 %22SELECT%22
  +%0A 
@@ -1409,19 +1409,22 @@
 %22SELECT%22
- +%0A
+%0A     
         
@@ -1426,24 +1426,25 @@
             
++
  %22  Database
@@ -1445,26 +1445,24 @@
 tabaseName,%22
- +
 %0A           
@@ -1461,24 +1461,30 @@
             
+     +
  %22  TableNam
@@ -1486,19 +1486,22 @@
 leName,%22
- +%0A
+%0A     
         
@@ -1507,16 +1507,17 @@
         
++
  %22  Last
@@ -1581,11 +1581,14 @@
 TE %22
- +%0A
+%0A     
     
@@ -1598,16 +1598,17 @@
         
++
  %22FROM D
@@ -1623,158 +1623,52 @@
 sV%22)
-;%0A        while (rs.next()) %7B%0A          System.out.printf(%22DB: %25s, table: %25s%25n%22, rs.getString(%22DatabaseName%22),%0A              rs.getString(%22TableName%22)
+) %7B%0A          assertThat(rs.next()).isFalse(
 );%0A 

Improve test case for TeradataSimulator