KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > examples > calcserver > TestCalculator


1 package com.mockobjects.examples.calcserver;
2
3 import com.mockobjects.util.TestCaseMo;
4
5 /**
6  * JUnit test case for CalculatorImplTest
7  */

8
9 public class TestCalculator extends TestCaseMo {
10     private static final Class JavaDoc THIS = TestCalculator.class;
11
12     Calculator myCalculator = new Calculator();
13
14
15     public TestCalculator(String JavaDoc name) {
16         super(name);
17     }
18
19
20     public static void main(String JavaDoc[] args) {
21         start(new String JavaDoc[]{ THIS.getName()});
22     }
23
24
25     public void testAdd() throws CalculatorException {
26         assertEquals("add", 9, myCalculator.calculate(5, 4, "/add"));
27     }
28
29
30     public void testBadOperation() {
31         try {
32             myCalculator.calculate(5, 4, "Bad operation");
33             fail("Should have thrown an exception");
34         } catch (CalculatorException expected) {
35         }
36     }
37
38
39     public void testSubtract() throws CalculatorException {
40         assertEquals("subtract", 1, myCalculator.calculate(5, 4, "/subtract"));
41     }
42 }
Popular Tags