01: package com.mockrunner.test.jms;
02:
03: import java.io.Serializable;
04:
05: import javax.jms.MessageNotWriteableException;
06:
07: import com.mockrunner.mock.jms.MockObjectMessage;
08: import com.mockrunner.mock.jms.MockTextMessage;
09:
10: import junit.framework.TestCase;
11:
12: public class MockObjectMessageTest extends TestCase {
13: public void testEquals() {
14: MockObjectMessage message = new MockObjectMessage("test");
15: assertTrue(message.equals(message));
16: assertTrue(new MockObjectMessage("test")
17: .equals(new MockObjectMessage("test")));
18: assertFalse(new MockObjectMessage("test")
19: .equals(new MockTextMessage("test")));
20: assertTrue(new MockObjectMessage(new Integer(1))
21: .equals(new MockObjectMessage(new Integer(1))));
22: assertFalse(new MockObjectMessage(new Double(1.1))
23: .equals(new MockObjectMessage(new Double(1.3))));
24: assertFalse(new MockObjectMessage(new Long(3)).equals(null));
25: assertFalse(new MockObjectMessage(null).equals(null));
26: assertTrue(new MockObjectMessage(null)
27: .equals(new MockObjectMessage(null)));
28: assertEquals(new MockObjectMessage(new Double(1.1)).hashCode(),
29: new MockObjectMessage(new Double(1.1)).hashCode());
30: assertEquals(new MockObjectMessage(null).hashCode(),
31: new MockObjectMessage(null).hashCode());
32: }
33:
34: public void testReadOnly() throws Exception {
35: MockObjectMessage message = new MockObjectMessage("test");
36: message.setObject(new Integer(2));
37: assertEquals(new Integer(2), message.getObject());
38: message.setReadOnly(true);
39: try {
40: message.setObject(new Integer(3));
41: fail();
42: } catch (MessageNotWriteableException exc) {
43: //should throw exception
44: }
45: assertEquals(new Integer(2), message.getObject());
46: message.clearBody();
47: message.setObject(new Integer(3));
48: assertEquals(new Integer(3), message.getObject());
49: }
50:
51: public void testClone() throws Exception {
52: MockObjectMessage message = new MockObjectMessage();
53: message.setObject("aText");
54: message.setStringProperty("string", "test");
55: MockObjectMessage newMessage = (MockObjectMessage) message
56: .clone();
57: assertNotSame(message, newMessage);
58: assertEquals(message, newMessage);
59: assertEquals("aText", newMessage.getObject());
60: assertEquals("test", newMessage.getStringProperty("string"));
61: message.setObject(new Integer(7));
62: newMessage = (MockObjectMessage) message.clone();
63: assertEquals(new Integer(7), newMessage.getObject());
64: TestObject testObject = new TestObject();
65: message.setObject(testObject);
66: newMessage = (MockObjectMessage) message.clone();
67: assertNotSame(testObject, newMessage.getObject());
68: }
69:
70: public void testToString() throws Exception {
71: MockObjectMessage message = new MockObjectMessage();
72: assertEquals(MockObjectMessage.class.getName() + ": null",
73: message.toString());
74: message.setObject(new Integer(3));
75: assertEquals(MockObjectMessage.class.getName() + ": 3", message
76: .toString());
77: message.setObject(new TestObject());
78: assertEquals(
79: MockObjectMessage.class.getName() + ": TestObject",
80: message.toString());
81: }
82:
83: public static class TestObject implements Serializable {
84: public String toString() {
85: return "TestObject";
86: }
87:
88: }
89: }
|