KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > calculator > acceptance > CalculatorAcceptanceTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.calculator.acceptance;
4
5 import junit.framework.TestCase;
6 import org.jmock.examples.calculator.Calculator;
7
8
9 public class CalculatorAcceptanceTest extends TestCase
10 {
11     private Calculator calculator;
12
13     public void setUp() {
14         calculator = new Calculator();
15     }
16
17     public void testLiteral() throws Exception JavaDoc {
18         assertEquals("should be 9", 9, calculator.calculate("9"), 0);
19     }
20
21     public void testSimpleCalculation() throws Exception JavaDoc {
22         assertEquals("should be 7", 7, calculator.calculate("1 + 2 * 3"), 0);
23     }
24
25     public void testCalculationWithVariables() throws Exception JavaDoc {
26         calculator.setVariable("x", "1 + 2");
27         calculator.setVariable("y", "x * 3");
28
29         assertEquals("should be 9", 9, calculator.calculate("y"), 0);
30     }
31
32     public void testCalculationWithParentheses() throws Exception JavaDoc {
33         assertEquals("should be 9", 9, calculator.calculate("(1+2)*3"), 0);
34     }
35 }
36
Popular Tags