[TestMethod] public void testWriteAndReadExternal() { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); mapStorage.writeExternal(objectOutputStream); objectOutputStream.flush(); FlyweightMapStorage newMapStorage = new FlyweightMapStorage(); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); newMapStorage.readExternal(objectInputStream); String expected = mapStorage.toString(); assertEquals(expected, newMapStorage.toString()); }
[TestMethod] public void testReadExternalThrowsIOExceptionWithMalformedData() { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeUTF("hello"); objectOutputStream.flush(); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); FlyweightMapStorage newMapStorage = new FlyweightMapStorage(); try { newMapStorage.readExternal(objectInputStream); fail(); } catch (IOException) { // Exception expected. } }
public FlyweightMapStorageTest() { mapStorage = new FlyweightMapStorage(); mapStorage.readFromSortedMap(areaCodeMap); }