@Test public void testReadWriteExternal() throws IOException, ClassNotFoundException, ISOException { // given ByteArrayOutputStream data = new ByteArrayOutputStream(); ObjectOutputStream ostr = new ObjectOutputStream(data); // when iSOAmount.writeExternal(ostr); ostr.close(); ObjectInputStream istr = new ObjectInputStream(new ByteArrayInputStream(data.toByteArray())); // then ISOAmount pickled = new ISOAmount(); pickled.readExternal(istr); istr.close(); assertThat(pickled.getAmountAsString(), is(iSOAmount.getAmountAsString())); }
@Test public void testBadReadAttemptISOException() throws IOException, ClassNotFoundException { iSOAmount = new ISOAmount() { @Override public void setValue(Object obj) throws ISOException { throw new ISOException("yikes!"); } }; ObjectInput in = mock(ObjectInput.class); try { iSOAmount.readExternal(in); } catch (IOException ioe) { assertThat(ioe.getMessage(), is("yikes!")); } }