SelectImpl extends BaseSqlPart implements Select { @Override public void prependTo(@NotNull final RawSqlBuilder builder) { for (int i = mColumns.length - 1; i >= 0; i--) { builder.prepend(mColumns[i]); if (i > 0) { builder.prepend(','); } } builder.prepend("SELECT "); } SelectImpl(@NotNull final String... columns); @NotNull @Override SelectFrom from(@NotNull final String tableName); @Override void prependTo(@NotNull final RawSqlBuilder builder); @Nullable @Override SqlPart previous();  }
@Test public void prependTo_withoutColumns_prependsProperSql() { SelectImpl select = new SelectImpl(); RawSqlBuilder builder = new RawSqlBuilderImpl(); select.prependTo(builder); assertThat(builder.toString(), is("SELECT *")); }
@Test public void prependTo_withOneColumn_prependsProperSql() { String[] columns = {"a"}; SelectImpl select = new SelectImpl(columns); RawSqlBuilder builder = new RawSqlBuilderImpl(); select.prependTo(builder); assertThat(builder.toString(), is("SELECT a")); }
@Test public void prependTo_withMultipleColumns_prependsProperSql() { String[] columns = {"a", "b", "c"}; SelectImpl select = new SelectImpl(columns); RawSqlBuilder builder = new RawSqlBuilderImpl(); select.prependTo(builder); assertThat(builder.toString(), is("SELECT a,b,c")); }