예제 #1
0
  @Test(expected = IOException.class)
  public void testSimpleSerializationFails() throws IOException {
    Trie trie = instance();

    assertTrue(trie.add("abc"));
    assertTrue(trie.add("cde"));

    OutputStream outputStream =
        new OutputStream() {
          @Override
          public void write(int b) throws IOException {
            throw new IOException("Fail");
          }
        };

    ((StreamSerializable) trie).serialize(outputStream);
  }
예제 #2
0
  @Test
  public void testSimpleSerialization() throws IOException {
    Trie trie = instance();

    assertTrue(trie.add("abc"));
    assertTrue(trie.add("cde"));
    assertEquals(2, trie.size());

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((StreamSerializable) trie).serialize(outputStream);

    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    Trie newTrie = instance();
    ((StreamSerializable) newTrie).deserialize(inputStream);

    assertTrue(newTrie.contains("abc"));
    assertTrue(newTrie.contains("cde"));
    assertEquals(2, trie.size());
  }