01: package com.mockrunner.test.jms;
02:
03: import javax.jms.MessageNotWriteableException;
04:
05: import junit.framework.TestCase;
06:
07: import com.mockrunner.mock.jms.MockTextMessage;
08:
09: public class MockTextMessageTest extends TestCase {
10: public void testEquals() {
11: MockTextMessage message = new MockTextMessage("test");
12: assertTrue(message.equals(message));
13: assertTrue(new MockTextMessage("test")
14: .equals(new MockTextMessage("test")));
15: assertFalse(new MockTextMessage("test")
16: .equals(new MockTextMessage("test1")));
17: assertFalse(new MockTextMessage("test").equals(null));
18: assertFalse(new MockTextMessage(null).equals(null));
19: assertTrue(new MockTextMessage(null)
20: .equals(new MockTextMessage(null)));
21: assertEquals(new MockTextMessage("test").hashCode(),
22: new MockTextMessage("test").hashCode());
23: assertEquals(new MockTextMessage(null).hashCode(),
24: new MockTextMessage(null).hashCode());
25: }
26:
27: public void testReadOnly() throws Exception {
28: MockTextMessage message = new MockTextMessage("test");
29: message.setText("test2");
30: assertEquals("test2", message.getText());
31: message.setReadOnly(true);
32: try {
33: message.setText("test3");
34: fail();
35: } catch (MessageNotWriteableException exc) {
36: //should throw exception
37: }
38: assertEquals("test2", message.getText());
39: message.clearBody();
40: message.setText("test3");
41: assertEquals("test3", message.getText());
42: }
43:
44: public void testClone() throws Exception {
45: MockTextMessage message = new MockTextMessage();
46: message.setText("aText");
47: message.setStringProperty("string", "test");
48: message.setJMSPriority(3);
49: MockTextMessage newMessage = (MockTextMessage) message.clone();
50: assertNotSame(message, newMessage);
51: assertEquals(message, newMessage);
52: assertEquals("aText", newMessage.getText());
53: assertEquals("test", newMessage.getStringProperty("string"));
54: assertEquals(3, newMessage.getJMSPriority());
55: }
56:
57: public void testToString() throws Exception {
58: MockTextMessage message = new MockTextMessage();
59: assertEquals(MockTextMessage.class.getName() + ": null",
60: message.toString());
61: message.setText("Hello World");
62: assertEquals(MockTextMessage.class.getName() + ": Hello World",
63: message.toString());
64: }
65: }
|