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 ; 7 import java.util.Map ; 8 9 12 public class JUnitEventSink implements EventSink { 13 14 protected static JUnitEventSink instance; 15 protected EventSink otherSink; 16 17 protected Map 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 count = (Integer )counters.get(event.getClass()); 38 if ( count == null ) { 39 count = new Integer ( 0 ); 40 } 41 counters.put ( event.getClass(), new Integer (count.intValue()+1) ); 42 if ( otherSink != null ) { 43 otherSink.notify(event); 44 } 45 } 46 47 public int getEventCount ( Class eventClass ) { 48 Integer count = (Integer )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 ( ); 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 |