ColumnsImpl extends BaseFinishedStatement implements CreateColumns { @Override public void prependTo(@NotNull final RawSqlBuilder builder) { builder.prepend(')'); for (int i = mColumns.length - 1; i >= 0; i--) { mColumns[i].prependTo(builder); if (i > 0) { builder.prepend(','); } } builder.prepend('('); } ColumnsImpl(@NotNull final Column[] columns, @NotNull final SqlPart previous); @NotNull @Override WithoutRowId withoutRowId(); @Override void prependTo(@NotNull final RawSqlBuilder builder); @Nullable @Override SqlPart previous();  }
@Test public void prependToWithoutColumns_prependsProperSql() { ColumnsImpl columns = new ColumnsImpl(new Column[0], mock(SqlPart.class)); RawSqlBuilder builder = new RawSqlBuilderImpl(); columns.prependTo(builder); assertThat(builder.toString(), is("()")); }
@Test public void prependToWithOneColumn_prependsProperSql() { ColumnsImpl columns = new ColumnsImpl(new Column[] {new ColumnImpl("a")}, mock(SqlPart.class)); RawSqlBuilder builder = new RawSqlBuilderImpl(); columns.prependTo(builder); assertThat(builder.toString(), is("(a)")); }
@Test public void prependToWithMultipleColumns_prependsProperSql() { Column[] cs = {column("a"), column("b"), column("c")}; ColumnsImpl columns = new ColumnsImpl(cs, mock(SqlPart.class)); RawSqlBuilder builder = new RawSqlBuilderImpl(); columns.prependTo(builder); assertThat(builder.toString(), is("(a,b,c)")); }