Last active
December 16, 2015 06:58
-
-
Save sureshnath/5394860 to your computer and use it in GitHub Desktop.
test simple xml serialisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> T testSerialisation(Class<? extends T> type, T expected) { | |
Serializer serializer = new Persister(); | |
StringWriter sw = new StringWriter(); | |
T actual = null; | |
try { | |
serializer.write(expected, sw); | |
} catch (Exception ex) { | |
LOG.error("testing serialisation failed", ex); | |
Assert.fail("testing serialisation failed"); | |
} | |
LOG.debug(sw.toString()); | |
try { | |
actual = serializer.read(type, sw.toString()); | |
} catch (Exception ex) { | |
LOG.error("testing de-serialisation failed", ex); | |
Assert.fail("testing de-serialisation failed"); | |
} | |
Assert.assertNotNull("de-serialised to null object", actual); | |
Assert.assertEquals("de-serialisation equals failed", expected, actual); | |
return actual; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment