public static String reformatSql(String sql) {
    char[] chars = sql.toCharArray();
    StringBuilder result = new StringBuilder(chars.length);

    for (int i = 0; i < chars.length; i++) {
      char c = chars[i];
      if (c == '\n' || c == '\t') {
        c = ' ';
      }
      if (Character.isWhitespace(c) && i > 0 && Character.isWhitespace(chars[i - 1])) {
        continue;
      }
      result.append(c);
    }
    return result.toString();
  }
@Test
  public void reformatSql() {
    assertThat(SqlLogFormatter.reformatSql("")).isEmpty();
    assertThat(SqlLogFormatter.reformatSql("select *")).isEqualTo("select *");
    assertThat(SqlLogFormatter.reformatSql("select *\nfrom issues")).isEqualTo("select * from issues");
    assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues");
    assertThat(SqlLogFormatter.reformatSql("select *\n   from issues")).isEqualTo("select * from issues");
    assertThat(SqlLogFormatter.reformatSql("select    *\n   from    issues")).isEqualTo("select * from issues");
    assertThat(SqlLogFormatter.reformatSql("select    *\n\t\t  from  \tissues")).isEqualTo("select * from issues");
  }