@Test
 public void shouldInstantiateByLocalMySqlConnectionInfo()
     throws SQLException, IOException, InterruptedException {
   SchemaDumper schemaDumper = new SchemaDumper(MySqlConnectionInfo.builder().build());
   try {
     schemaDumper.dump(SQL_FOR_TEST);
     assertTrue(true);
   } catch (CommunicationsException e) {
     assumeTrue("MySQL maybe not launched", false);
   } catch (Exception e) {
     assertTrue(false);
   }
 }
 @Test
 public void shouldInstantiateByMysqldumpPath()
     throws SQLException, IOException, InterruptedException {
   SchemaDumper schemaDumper = new SchemaDumper("mysqldump");
   try {
     schemaDumper.dump(SQL_FOR_TEST);
     assertTrue(true);
   } catch (CommunicationsException e) {
     assumeTrue("MySQL maybe not launched", false);
   } catch (Exception e) {
     assertTrue(false);
   }
 }
    @Test
    public void shouldDumpFromRemoteMySql() throws SQLException, IOException, InterruptedException {
      MySqlConnectionInfo connInfo = MySqlConnectionInfo.builder().build();

      String tempDbName =
          new StringBuilder()
              .append("tmp_")
              .append(UUID.randomUUID().toString().replaceAll("-", ""))
              .toString();
      String mysqlUrl = connInfo.getJdbcUrl();
      String user = connInfo.getUser();
      String pass = connInfo.getPass();

      try (Connection connection = DriverManager.getConnection(mysqlUrl, user, pass)) {
        try (Statement stmt = connection.createStatement()) {
          stmt.executeUpdate("CREATE DATABASE " + tempDbName);
        }
        try (Statement stmt = connection.createStatement()) {
          stmt.executeUpdate("USE " + tempDbName + "; " + SQL_FOR_TEST);
        }
        schemaDumper.dumpFromRemoteDb(tempDbName, connInfo);
      } catch (Exception e) {
        throw e;
      } finally {
        try (Connection connectionToTeardown = DriverManager.getConnection(mysqlUrl, user, pass)) {
          try (Statement stmt = connectionToTeardown.createStatement()) {
            stmt.executeUpdate("DROP DATABASE " + tempDbName);
          }
        } catch (CommunicationsException e) {
          assumeTrue("MySQL maybe not launched", false);
        }
      }
      assertTrue(true);
    }
 @Test
 public void shouldDumpBySqlString() throws SQLException, IOException, InterruptedException {
   try {
     schemaDumper.dump(SQL_FOR_TEST);
     assertTrue(true);
   } catch (CommunicationsException e) {
     assumeTrue("MySQL maybe not launched", false);
   } catch (Exception e) {
     assertTrue(false);
   }
 }
    @Test
    public void shouldDumpBySqlFileWithSpecifiedCharset()
        throws IOException, SQLException, InterruptedException {
      File sqlFile = File.createTempFile("tempsql", ".sql");

      try (BufferedWriter bufferedWriter =
          new BufferedWriter(
              new OutputStreamWriter(new FileOutputStream(sqlFile), Charset.forName("EUC-JP")))) {
        bufferedWriter.write(SQL_FOR_TEST);
      }

      try {
        schemaDumper.dump(sqlFile, Charset.forName("EUC-JP"));
        assertTrue(true);
      } catch (CommunicationsException e) {
        assumeTrue("MySQL maybe not launched", false);
      } catch (Exception e) {
        assertTrue(false);
      } finally {
        sqlFile.delete();
      }
    }