OrderByImpl extends BaseFinishedSelectStatement implements OrderBy { @Override public void prependTo(@NotNull final RawSqlBuilder builder) { for (int i = mTerms.length - 1; i >= 0; i--) { builder.prepend(mTerms[i]); if (i > 0) { builder.prepend(','); } } builder.prepend("ORDER BY "); } OrderByImpl(@NotNull final String[] terms, @NotNull final SqlPart previous); @Override Limit limit(final long limit); @Override void prependTo(@NotNull final RawSqlBuilder builder); @Nullable @Override SqlPart previous();  }
@Test public void prependTo_withSingleItem_prependsProperSql() { OrderByImpl orderBy = new OrderByImpl(new String[] {"a"}, mock(SqlPart.class)); RawSqlBuilder builder = new RawSqlBuilderImpl(); orderBy.prependTo(builder); assertThat(builder.toString(), is("ORDER BY a")); }
@Test public void prependTo_withMultipleItems_prependsProperSql() { OrderByImpl orderBy = new OrderByImpl(new String[] {"a", "b", "c"}, mock(SqlPart.class)); RawSqlBuilder builder = new RawSqlBuilderImpl(); orderBy.prependTo(builder); assertThat(builder.toString(), is("ORDER BY a,b,c")); }