View Javadoc
1   package org.dbunit.dataset.common.handlers;
2   
3   import java.util.List;
4   
5   import mockmaker.ExceptionalReturnValue;
6   import mockmaker.ReturnValues;
7   import mockmaker.VoidReturnValues;
8   
9   import com.mockobjects.ExpectationCounter;
10  import com.mockobjects.ExpectationList;
11  
12  /**
13   * @author gommma (gommma AT users.sourceforge.net)
14   * @author Last changed by: $Author$
15   * @version $Revision$ $Date$
16   * @since 2.4.0
17   */
18  public class MockHandler extends AbstractPipelineComponent{
19     private ExpectationCounter mySetSuccessorCalls = new ExpectationCounter("org.dbunit.dataset.csv.handlers.AbstractPipelineComponent SetSuccessorCalls");
20     private ReturnValues myActualSetSuccessorReturnValues = new VoidReturnValues(false);
21     private ExpectationList mySetSuccessorParameter0Values = new ExpectationList("org.dbunit.dataset.csv.handlers.AbstractPipelineComponent org.dbunit.dataset.csv.handlers.Handler");
22     private ExpectationCounter myGetSinkCalls = new ExpectationCounter("org.dbunit.dataset.csv.handlers.AbstractPipelineComponent GetSinkCalls");
23     private ReturnValues myActualGetSinkReturnValues = new ReturnValues(false);
24     private ExpectationCounter myHandleCalls = new ExpectationCounter("org.dbunit.dataset.csv.handlers.AbstractPipelineComponent HandleCalls");
25     private ReturnValues myActualHandleReturnValues = new VoidReturnValues(false);
26     private ExpectationList myHandleParameter0Values = new ExpectationList("org.dbunit.dataset.csv.handlers.AbstractPipelineComponent char");
27     public void setExpectedSetSuccessorCalls(int calls){
28        mySetSuccessorCalls.setExpected(calls);
29     }
30     public void addExpectedSetSuccessorValues(Handler arg0){
31        mySetSuccessorParameter0Values.addExpected(arg0);
32     }
33     public void setSuccessor(PipelineComponent arg0){
34        super.setSuccessor(arg0);
35        mySetSuccessorCalls.inc();
36        mySetSuccessorParameter0Values.addActual(arg0);
37        Object nextReturnValue = myActualSetSuccessorReturnValues.getNext();
38        if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
39            throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
40     }
41     public void setupExceptionSetSuccessor(Throwable arg){
42        myActualSetSuccessorReturnValues.add(new ExceptionalReturnValue(arg));
43     }
44     public void setExpectedGetSinkCalls(int calls){
45        myGetSinkCalls.setExpected(calls);
46     }
47     public void setupExceptionGetSink(Throwable arg){
48        myActualGetSinkReturnValues.add(new ExceptionalReturnValue(arg));
49     }
50     public void setupGetSink(List arg){
51        myActualGetSinkReturnValues.add(arg);
52     }
53     public void setExpectedHandleCalls(int calls){
54        myHandleCalls.setExpected(calls);
55     }
56     public void addExpectedHandleValues(char arg0){
57        myHandleParameter0Values.addExpected(new Character(arg0));
58     }
59     public void handle(char arg0) throws IllegalInputCharacterException, PipelineException{
60        myHandleCalls.inc();
61        myHandleParameter0Values.addActual(new Character(arg0));
62        Object nextReturnValue = myActualHandleReturnValues.getNext();
63        if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof IllegalInputCharacterException)
64            throw (IllegalInputCharacterException)((ExceptionalReturnValue)nextReturnValue).getException();
65        if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
66            throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
67         super.handle(arg0);
68     }
69     public void setupExceptionHandle(Throwable arg){
70        myActualHandleReturnValues.add(new ExceptionalReturnValue(arg));
71     }
72     public void verify(){
73        mySetSuccessorCalls.verify();
74        mySetSuccessorParameter0Values.verify();
75        myGetSinkCalls.verify();
76        myHandleCalls.verify();
77        myHandleParameter0Values.verify();
78     }
79  	public boolean canHandle(char c) throws IllegalInputCharacterException {
80  		return false;
81  	}
82  
83  }