コード例 #1
0
        [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());
        }
コード例 #2
0
        [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.
            }
        }
コード例 #3
0
 public FlyweightMapStorageTest()
 {
     mapStorage = new FlyweightMapStorage();
     mapStorage.readFromSortedMap(areaCodeMap);
 }