### Question:
JmsObjectMessage extends JmsMessage implements ObjectMessage { @Override public void setObject(Serializable newObject) throws JMSException { checkReadOnlyBody(); try { this.facade.setObject(newObject); } catch (Exception e) { MessageFormatException jmsEx = new MessageFormatException("Failed to serialize object:" + e.getMessage()); jmsEx.setLinkedException(e); jmsEx.initCause(e); throw jmsEx; } } JmsObjectMessage(JmsObjectMessageFacade facade); @Override JmsObjectMessage copy(); @Override void setObject(Serializable newObject); @Override Serializable getObject(); @Override boolean isBodyAssignableTo(@SuppressWarnings("rawtypes") Class target); @Override String toString();  }### Answer:
@Test public void testReceivedObjectMessageThrowsMessageNotWriteableExceptionOnSetObject() throws Exception { String content = "myStringContent"; JmsObjectMessageFacade facade = new JmsTestObjectMessageFacade(); facade.setObject(content); JmsObjectMessage objectMessage = new JmsObjectMessage(facade); objectMessage.onDispatch(); try { objectMessage.setObject("newObject"); fail("Expected exception to be thrown"); } catch (MessageNotWriteableException mnwe) { } }
@Test public void testClearBodyOnReceivedObjectMessageMakesMessageWritable() throws Exception { String content = "myStringContent"; JmsObjectMessageFacade facade = new JmsTestObjectMessageFacade(); facade.setObject(content); JmsObjectMessage objectMessage = new JmsObjectMessage(facade); objectMessage.onDispatch(); assertTrue("Message should not be writable", objectMessage.isReadOnlyBody()); objectMessage.clearBody(); assertFalse("Message should be writable", objectMessage.isReadOnlyBody()); }
@Test public void testSetObjectWithNonSerializableThrowsJMSMFE() throws Exception { Map<String, Object> origMap = new HashMap<String, Object>(); origMap.put("key1", "value1"); origMap.put("notSerializable", new NotSerializable()); JmsObjectMessage objectMessage = factory.createObjectMessage(); try { objectMessage.setObject((Serializable) origMap); fail("Expected exception to be thrown"); } catch (MessageFormatException mfe) { } }
@Test public void testSetObject() throws JMSException { JmsObjectMessage msg = factory.createObjectMessage(); String str = "testText"; msg.setObject(str); assertEquals(str, msg.getObject()); }