KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > test > interceptor > mock > MockObject


1 package org.snipsnap.test.interceptor.mock;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 public class MockObject {
7   private Map JavaDoc callCount;
8
9   public MockObject() {
10     callCount = new HashMap JavaDoc();
11   }
12
13   public void clearCalls() {
14     callCount = new HashMap JavaDoc();
15   }
16
17   protected void inc(String JavaDoc name) {
18     if (callCount.containsKey(name)) {
19       int count = ((Integer JavaDoc) callCount.get(name)).intValue();
20       count++;
21       callCount.put(name, new Integer JavaDoc(count));
22     } else {
23       callCount.put(name, new Integer JavaDoc(1));
24     }
25   }
26
27   public int getCount(String JavaDoc name) {
28      if (callCount.containsKey(name)) {
29        return ((Integer JavaDoc) callCount.get(name)).intValue();
30      } else {
31        return 1;
32      }
33   }
34 }
35
Popular Tags