1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.velocity.exception.MathException;
23 import org.apache.velocity.runtime.RuntimeConstants;
24
25
26
27
28 public class StrictMathTestCase extends BaseTestCase
29 {
30 public StrictMathTestCase(String name)
31 {
32 super(name);
33 }
34
35 public void setUp() throws Exception
36 {
37 super.setUp();
38 engine.setProperty(RuntimeConstants.STRICT_MATH, Boolean.TRUE);
39 context.put("num", new Integer(5));
40 context.put("zero", new Integer(0));
41 }
42
43 protected void assertNullMathEx(String operation)
44 {
45 String leftnull = "#set( $foo = $null "+operation+" $num )";
46 assertEvalException(leftnull, MathException.class);
47 String rightnull = "#set( $foo = $num "+operation+" $null )";
48 assertEvalException(rightnull, MathException.class);
49 }
50
51 protected void assertImaginaryMathEx(String operation)
52 {
53 String infinity = "#set( $foo = $num "+operation+" $zero )";
54 assertEvalException(infinity, MathException.class);
55 }
56
57
58 public void testAdd()
59 {
60 assertNullMathEx("+");
61 }
62
63 public void testSub()
64 {
65 assertNullMathEx("-");
66 }
67
68 public void testMul()
69 {
70 assertNullMathEx("*");
71 }
72
73 public void testMod()
74 {
75 assertNullMathEx("%");
76 assertImaginaryMathEx("%");
77 }
78
79 public void testDiv()
80 {
81 assertNullMathEx("/");
82 assertImaginaryMathEx("/");
83 }
84
85 }