01: package com.mockrunner.mock.jms;
02:
03: import javax.jms.JMSException;
04: import javax.jms.MessageNotWriteableException;
05: import javax.jms.TextMessage;
06:
07: /**
08: * Mock implementation of JMS <code>TextMessage</code>.
09: */
10: public class MockTextMessage extends MockMessage implements TextMessage {
11: private String text;
12:
13: public MockTextMessage() {
14: this (null);
15: }
16:
17: public MockTextMessage(String text) {
18: this .text = text;
19: }
20:
21: public void setText(String text) throws JMSException {
22: if (!isInWriteMode()) {
23: throw new MessageNotWriteableException(
24: "Message is in read mode");
25: }
26: this .text = text;
27: }
28:
29: public String getText() throws JMSException {
30: return text;
31: }
32:
33: public String toString() {
34: return this .getClass().getName() + ": " + text;
35: }
36:
37: public void clearBody() throws JMSException {
38: super .clearBody();
39: text = null;
40: }
41:
42: /**
43: * Compares the underlying String. If the Strings of
44: * both messages are <code>null</code>, this
45: * method returns <code>true</code>.
46: */
47: public boolean equals(Object otherObject) {
48: if (null == otherObject)
49: return false;
50: if (!(otherObject instanceof MockTextMessage))
51: return false;
52: MockTextMessage otherMessage = (MockTextMessage) otherObject;
53: if (null == text && null == otherMessage.text)
54: return true;
55: return text.equals(otherMessage.text);
56: }
57:
58: public int hashCode() {
59: if (null == text)
60: return 0;
61: return text.hashCode();
62: }
63: }
|