### Question:
CaseBuilder { public Initial when(Predicate b) { return new Initial(b); }  Initial when(Predicate b);  }### Answer:
@Test public void general() { SimpleExpression<Object> expr = new CaseBuilder() .when(Expressions.TRUE).then(new Object()) .otherwise(null); assertNotNull(expr); }
@Test public void booleanTyped() { Customer c = alias(Customer.class, "customer"); BooleanExpression cases = new CaseBuilder() .when($(c.getAnnualSpending()).gt(10000)).then(true) .otherwise(false); assertEquals( "case " + "when customer.annualSpending > 10000 then true " + "else false " + "end", cases.toString()); }
@Test public void booleanTyped_predicate() { Customer c = alias(Customer.class, "customer"); BooleanExpression cases = new CaseBuilder() .when($(c.getAnnualSpending()).gt(20000)).then(false) .when($(c.getAnnualSpending()).gt(10000)).then(true) .otherwise(false); assertEquals( "case " + "when customer.annualSpending > 20000 then false " + "when customer.annualSpending > 10000 then true " + "else false " + "end", cases.toString()); }
@Test public void enumTyped() { Customer c = alias(Customer.class, "customer"); EnumExpression<Gender> cases = new CaseBuilder() .when($(c.getAnnualSpending()).gt(10000)).then(Gender.MALE) .otherwise(Gender.FEMALE); assertEquals( "case " + "when customer.annualSpending > 10000 then MALE " + "else FEMALE " + "end", cases.toString()); }
@Test public void numberTyped() { Customer c = alias(Customer.class, "customer"); NumberExpression<Integer> cases = new CaseBuilder() .when($(c.getAnnualSpending()).gt(10000)).then(1) .when($(c.getAnnualSpending()).gt(5000)).then(2) .when($(c.getAnnualSpending()).gt(2000)).then(3) .otherwise(4); assertEquals( "case " + "when customer.annualSpending > 10000 then 1 " + "when customer.annualSpending > 5000 then 2 " + "when customer.annualSpending > 2000 then 3 " + "else 4 " + "end", cases.toString()); }
@Test public void stringTyped() { Customer c = alias(Customer.class, "customer"); StringExpression cases = new CaseBuilder() .when($(c.getAnnualSpending()).gt(10000)).then("Premier") .when($(c.getAnnualSpending()).gt(5000)).then("Gold") .when($(c.getAnnualSpending()).gt(2000)).then("Silver") .otherwise("Bronze"); assertEquals( "case " + "when customer.annualSpending > 10000 then Premier " + "when customer.annualSpending > 5000 then Gold " + "when customer.annualSpending > 2000 then Silver " + "else Bronze " + "end", cases.toString()); }