@Test void sql() { CaseExpression<String> sut = new CaseExpression<>(condition, expression1); when(condition.sql(scope)).thenReturn("CONDITION"); when(expression1.sql(scope)).thenReturn("EXPRESSION"); String sql = sut.sql(scope); assertThat(sql, is("case when CONDITION then EXPRESSION end")); verifyNoMoreInteractions(condition, expression1, scope); }
@Override public String sql(Scope scope) { return String.format("case %s%s end", cases.stream().map(c -> String.format("when %s then %s", c.item1().sql(scope), c.item2().sql(scope))).collect(joining(" ")), orElse.map(e -> " else " + e.sql(scope)).orElse("")); }
CaseExpression implements TypedExpression<T> { @Override public String sql(Scope scope) { return String.format("case %s%s end", cases.stream().map(c -> String.format("when %s then %s", c.item1().sql(scope), c.item2().sql(scope))).collect(joining(" ")), orElse.map(e -> " else " + e.sql(scope)).orElse("")); } }
CaseExpression implements TypedExpression<T> { @Override public String sql(Scope scope) { return String.format("case %s%s end", cases.stream().map(c -> String.format("when %s then %s", c.item1().sql(scope), c.item2().sql(scope))).collect(joining(" ")), orElse.map(e -> " else " + e.sql(scope)).orElse("")); } CaseExpression(BooleanExpression booleanExpression, TypedExpression<T> value); }
CaseExpression implements TypedExpression<T> { @Override public String sql(Scope scope) { return String.format("case %s%s end", cases.stream().map(c -> String.format("when %s then %s", c.item1().sql(scope), c.item2().sql(scope))).collect(joining(" ")), orElse.map(e -> " else " + e.sql(scope)).orElse("")); } CaseExpression(BooleanExpression booleanExpression, TypedExpression<T> value); @Override String sql(Scope scope); @Override Stream<Object> args(Scope scope); @Override Precedence precedence(); @Override String label(Scope scope); @Override RowMapper<T> rowMapper(Scope scope, Optional<String> label); @Override TypeToken<T> type(); TypedExpression<T> orElse(T value); TypedExpression<T> orElse(TypedExpression<T> value); TypedExpression<T> orElse(Function1<R,T> method); TypedExpression<T> orElse(FunctionOptional1<R,T> method); TypedExpression<T> orElse(String alias, Function1<R,T> method); TypedExpression<T> orElse(String alias, FunctionOptional1<R,T> method); TypedExpression<T> orElse(Alias<R> alias, Function1<R,T> method); TypedExpression<T> orElse(Alias<R> alias, FunctionOptional1<R,T> method); ExpressionBuilder<X,InSubsequentWhenExpectingThen> when(X val); ExpressionBuilder<X,InSubsequentWhenExpectingThen> when(TypedExpression<X> expression); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(FunctionOptional1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(String alias, Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(String alias, FunctionOptional1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Alias<X> alias, Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Alias<X> alias, FunctionOptional1<X,R> method); }
CaseExpression implements TypedExpression<T> { @Override public String sql(Scope scope) { return String.format("case %s%s end", cases.stream().map(c -> String.format("when %s then %s", c.item1().sql(scope), c.item2().sql(scope))).collect(joining(" ")), orElse.map(e -> " else " + e.sql(scope)).orElse("")); } CaseExpression(BooleanExpression booleanExpression, TypedExpression<T> value); @Override String sql(Scope scope); @Override Stream<Object> args(Scope scope); @Override Precedence precedence(); @Override String label(Scope scope); @Override RowMapper<T> rowMapper(Scope scope, Optional<String> label); @Override TypeToken<T> type(); TypedExpression<T> orElse(T value); TypedExpression<T> orElse(TypedExpression<T> value); TypedExpression<T> orElse(Function1<R,T> method); TypedExpression<T> orElse(FunctionOptional1<R,T> method); TypedExpression<T> orElse(String alias, Function1<R,T> method); TypedExpression<T> orElse(String alias, FunctionOptional1<R,T> method); TypedExpression<T> orElse(Alias<R> alias, Function1<R,T> method); TypedExpression<T> orElse(Alias<R> alias, FunctionOptional1<R,T> method); ExpressionBuilder<X,InSubsequentWhenExpectingThen> when(X val); ExpressionBuilder<X,InSubsequentWhenExpectingThen> when(TypedExpression<X> expression); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(FunctionOptional1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(String alias, Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(String alias, FunctionOptional1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Alias<X> alias, Function1<X,R> method); ExpressionBuilder<R,InSubsequentWhenExpectingThen> when(Alias<X> alias, FunctionOptional1<X,R> method);  }