KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > jms > MockConnection


1 package com.mockobjects.jms;
2
3 import javax.jms.Connection JavaDoc;
4 import javax.jms.ConnectionMetaData JavaDoc;
5 import javax.jms.ExceptionListener JavaDoc;
6 import javax.jms.JMSException JavaDoc;
7 import com.mockobjects.ExpectationCounter;
8 import com.mockobjects.MockObject;
9
10 public class MockConnection extends MockObject implements Connection JavaDoc {
11
12     protected ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockConnection.close");
13     protected ExpectationCounter myStartCalls = new ExpectationCounter("CommonMockConnection.start");
14     protected ExpectationCounter myStopCalls = new ExpectationCounter("CommonMockConnection.stop");
15
16     private JMSException JavaDoc myException;
17
18     public void close() throws JMSException JavaDoc {
19         myCloseCalls.inc();
20         throwExceptionIfAny();
21     }
22
23     public String JavaDoc getClientID() throws JMSException JavaDoc {
24         notImplemented();
25         return null;
26     }
27
28     public ExceptionListener JavaDoc getExceptionListener() throws JMSException JavaDoc {
29         notImplemented();
30         return null;
31     }
32
33     public ConnectionMetaData JavaDoc getMetaData() throws JMSException JavaDoc {
34         notImplemented();
35         return null;
36     }
37
38     public void setClientID(String JavaDoc clientID) throws JMSException JavaDoc {
39         notImplemented();
40     }
41
42     public void setExceptionListener(ExceptionListener JavaDoc listener) throws JMSException JavaDoc {
43         //does nothing
44
}
45
46     public void start() throws JMSException JavaDoc {
47         myStartCalls.inc();
48         throwExceptionIfAny();
49     }
50
51     public void stop() throws JMSException JavaDoc {
52         myStopCalls.inc();
53         throwExceptionIfAny();
54     }
55
56     public void setExpectedCloseCalls(int callCount) {
57         myCloseCalls.setExpected(callCount);
58     }
59
60     public void setExpectedStartCalls(int callCount) {
61         myStartCalls.setExpected(callCount);
62     }
63
64     public void setExpectedStopCalls(int callCount) {
65         myStopCalls.setExpected(callCount);
66     }
67
68     public void setupThrowException(JMSException JavaDoc e) {
69         myException = e;
70     }
71
72     protected void throwExceptionIfAny() throws JMSException JavaDoc {
73         if (null != myException) {
74             throw myException;
75         }
76     }
77 }
78
Popular Tags