1 package com.mockobjects.jms; 2 3 import javax.jms.Connection ; 4 import javax.jms.ConnectionMetaData ; 5 import javax.jms.ExceptionListener ; 6 import javax.jms.JMSException ; 7 import com.mockobjects.ExpectationCounter; 8 import com.mockobjects.MockObject; 9 10 public class MockConnection extends MockObject implements Connection { 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 myException; 17 18 public void close() throws JMSException { 19 myCloseCalls.inc(); 20 throwExceptionIfAny(); 21 } 22 23 public String getClientID() throws JMSException { 24 notImplemented(); 25 return null; 26 } 27 28 public ExceptionListener getExceptionListener() throws JMSException { 29 notImplemented(); 30 return null; 31 } 32 33 public ConnectionMetaData getMetaData() throws JMSException { 34 notImplemented(); 35 return null; 36 } 37 38 public void setClientID(String clientID) throws JMSException { 39 notImplemented(); 40 } 41 42 public void setExceptionListener(ExceptionListener listener) throws JMSException { 43 } 45 46 public void start() throws JMSException { 47 myStartCalls.inc(); 48 throwExceptionIfAny(); 49 } 50 51 public void stop() throws JMSException { 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 e) { 69 myException = e; 70 } 71 72 protected void throwExceptionIfAny() throws JMSException { 73 if (null != myException) { 74 throw myException; 75 } 76 } 77 } 78 | Popular Tags |