/** @throws IOException */ @Test public void nonSerializableTypeDetection() throws IOException { SerializableChecker serializableChecker = new SerializableChecker(new NotSerializableException()); String exceptionMessage = null; try { serializableChecker.writeObject(new TestType2()); } catch (WicketNotSerializableException e) { exceptionMessage = e.getMessage(); } assertTrue(exceptionMessage.contains(NonSerializableType.class.getName())); }
/** * Asserting an meaningful message get logged on console when serializable checker is testing * problematic {@link Object#equals(Object)} method implementations. * * @see <a href="https://issues.apache.org/jira/browse/WICKET-3354">WICKET-3354</a> * @throws IOException */ @Test public void runtimeExceptionTolerance() throws IOException { Logger logger = LogManager.getLogger(SerializableChecker.class); logger.setLevel(Level.WARN); Log4jEventHistory logHistory = new Log4jEventHistory(); logger.addAppender(logHistory); SerializableChecker serializableChecker = new SerializableChecker(new NotSerializableException()); try { serializableChecker.writeObject(new TestType1()); String expectedMessage = "Wasn't possible to check the object class org.apache.wicket.util.io.SerializableCheckerTest$ProblematicType possible due an problematic implementation of equals method"; assertTrue(logHistory.contains(Level.WARN, expectedMessage)); } catch (TestException notMeaningfulException) { fail("Should have just logged on console, the checker is after another problem"); } }
/** * Test {@link ValueMap} serializability. * * @throws IOException */ @Test public void valueMap() throws IOException { SerializableChecker checker = new SerializableChecker(new NotSerializableException()); checker.writeObject(new ValueMap()); }