CertificateAdapter extends XmlAdapter<String, Certificate> { @Override public String marshal(Certificate v) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); v.encode(outStream); return ArrayConverter.bytesToHexString(outStream.toByteArray()); }  @Override Certificate unmarshal(String v); @Override String marshal(Certificate v);  }
@Test public void testCorrectMarshal() throws IOException, Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); certificate.encode(outStream); String correctCertificateString = ArrayConverter.bytesToHexString(outStream.toByteArray()); String marshalledCertificateString = certificateAdapter.marshal(certificate); assertEquals(marshalledCertificateString, correctCertificateString); }
@Test(expected = Exception.class) public void testMarshalException() throws Exception { certificateAdapter.marshal(null); }