com.mockrunner.test.jms.MockTextMessageTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.test.jms;
import javax.jms.MessageNotWriteableException;
import junit.framework.TestCase;
import com.mockrunner.mock.jms.MockTextMessage;
public class MockTextMessageTest extends TestCase
{
public void testEquals()
{
MockTextMessage message = new MockTextMessage("test");
assertTrue(message.equals(message));
assertTrue(new MockTextMessage("test").equals(new MockTextMessage("test")));
assertFalse(new MockTextMessage("test").equals(new MockTextMessage("test1")));
assertFalse(new MockTextMessage("test").equals(null));
assertFalse(new MockTextMessage(null).equals(null));
assertTrue(new MockTextMessage(null).equals(new MockTextMessage(null)));
assertEquals(new MockTextMessage("test").hashCode(), new MockTextMessage("test").hashCode());
assertEquals(new MockTextMessage(null).hashCode(), new MockTextMessage(null).hashCode());
}
public void testReadOnly() throws Exception
{
MockTextMessage message = new MockTextMessage("test");
message.setText("test2");
assertEquals("test2", message.getText());
message.setReadOnly(true);
try
{
message.setText("test3");
fail();
}
catch(MessageNotWriteableException exc)
{
//should throw exception
}
assertEquals("test2", message.getText());
message.clearBody();
message.setText("test3");
assertEquals("test3", message.getText());
}
public void testClone() throws Exception
{
MockTextMessage message = new MockTextMessage();
message.setText("aText");
message.setStringProperty("string", "test");
message.setJMSPriority(3);
MockTextMessage newMessage = (MockTextMessage)message.clone();
assertNotSame(message, newMessage);
assertEquals(message, newMessage);
assertEquals("aText", newMessage.getText());
assertEquals("test", newMessage.getStringProperty("string"));
assertEquals(3, newMessage.getJMSPriority());
}
public void testToString() throws Exception
{
MockTextMessage message = new MockTextMessage();
assertEquals(MockTextMessage.class.getName() + ": null", message.toString());
message.setText("Hello World");
assertEquals(MockTextMessage.class.getName() + ": Hello World", message.toString());
}
}