KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mockobjects > plugin > JUnitEventSink


1 package net.javacoding.jspider.mockobjects.plugin;
2
3 import net.javacoding.jspider.api.event.EventSink;
4 import net.javacoding.jspider.api.event.JSpiderEvent;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 /**
10  * $Id: JUnitEventSink.java,v 1.7 2003/03/27 17:44:32 vanrogu Exp $
11  */

12 public class JUnitEventSink implements EventSink {
13
14     protected static JUnitEventSink instance;
15     protected EventSink otherSink;
16
17     protected Map JavaDoc counters;
18
19     private JUnitEventSink ( ) {
20         reset ( );
21     }
22
23     public static synchronized JUnitEventSink getInstance ( ) {
24         if ( instance == null ) {
25             instance = new JUnitEventSink();
26         }
27         return instance;
28     }
29
30     public void notify(JSpiderEvent event) {
31         System.out.println("JUnit Plugin : " + event.getClass() );
32
33         if ( event.isError() ) {
34             System.out.println(event);
35         }
36
37         Integer JavaDoc count = (Integer JavaDoc)counters.get(event.getClass());
38         if ( count == null ) {
39             count = new Integer JavaDoc ( 0 );
40         }
41         counters.put ( event.getClass(), new Integer JavaDoc(count.intValue()+1) );
42         if ( otherSink != null ) {
43             otherSink.notify(event);
44         }
45     }
46
47     public int getEventCount ( Class JavaDoc eventClass ) {
48         Integer JavaDoc count = (Integer JavaDoc)counters.get(eventClass);
49         if ( count == null ) {
50             return 0;
51         } else {
52             return count.intValue();
53         }
54     }
55
56     public void reset ( ) {
57       this.counters = new HashMap JavaDoc ( );
58       this.otherSink = null;
59     }
60
61     public void setOtherSink ( EventSink otherSink ) {
62         this.otherSink = otherSink;
63     }
64
65     public void initialize() {
66     }
67
68     public void shutdown() {
69     }
70 }
71
Popular Tags