### Question:
SAMLObject extends SAMLBase<T, T> { private void writeObject(ObjectOutputStream out) throws IOException { try { if (serializedObject == null) { serializedObject = XMLHelper.nodeToString(marshallMessage(getObject())); } out.writeUTF((String) serializedObject); } catch (MessageEncodingException e) { log.error("Error serializing SAML object", e); throw new IOException("Error serializing SAML object: " + e.getMessage()); } } SAMLObject(T object); @Override T getObject();  }### Answer:
@Test(expected = IOException.class) public void testMarshallingError() throws Exception { TestObject to = new TestObject("xxx", "", ""); SAMLObject<TestObject> tso = new SAMLObject<TestObject>(to); Marshaller mock = createMock(Marshaller.class); Configuration.getMarshallerFactory().registerMarshaller(to.getElementQName(), mock); expect(mock.marshall(to)).andThrow(new MarshallingException("Error")); replay(mock); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(outStream); stream.writeObject(tso); verify(mock); }