public void testGetWhenExpression() {
helpTestWhenExpressions(example(3), 3);
}
public void testSetWhen() {
CaseExpression caseExpr = example(4);
// Both are nulls
try {
caseExpr.setWhen(null, null);
fail("Setting WHEN and THEN to null should have failed."); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenExpressions(caseExpr, 4);
helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(getWhenExpressions(2), null);
fail("Setting THEN to null should have failed."); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenExpressions(caseExpr, 4);
helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(null, getThenExpressions(2));
fail("Setting WHEN to null should have failed."); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenExpressions(caseExpr, 4);
helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(getWhenExpressions(0), getThenExpressions(0));
fail("Setting WHEN and THEN to empty lists should have failed."); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenExpressions(caseExpr, 4);
helpTestThenExpressions(caseExpr, 4);
}
caseExpr.setWhen(TestSearchedCaseExpression.getWhenCriteria(3), getThenExpressions(3));
caseExpr.setWhen(getWhenExpressions(3), TestSearchedCaseExpression.getWhenCriteria(3));
ArrayList whens = new ArrayList();
whens.add(new Constant("abc")); //$NON-NLS-1$
whens.add(new Constant("xyz")); //$NON-NLS-1$
ArrayList thens = new ArrayList();
thens.add(new Constant(new Integer(20000)));
thens.add(new Constant(new Integer(30000)));
caseExpr.setWhen(whens, thens);
assertEquals(2, caseExpr.getWhenCount());
assertEquals(new Constant("abc"), caseExpr.getWhenExpression(0)); //$NON-NLS-1$
assertEquals(new Constant("xyz"), caseExpr.getWhenExpression(1)); //$NON-NLS-1$
assertEquals(new Constant(new Integer(20000)), caseExpr.getThenExpression(0));
assertEquals(new Constant(new Integer(30000)), caseExpr.getThenExpression(1));
}