Github user eolivelli commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/726#discussion_r236804588
  
    --- Diff: 
zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java ---
    @@ -41,4 +42,136 @@ public void testReadStringCheckLength() {
                         
e.getMessage().startsWith(BinaryInputArchive.UNREASONBLE_LENGTH));
             }
         }
    +
    +    public interface TestWriter {
    +        void write(OutputArchive oa) throws IOException;
    +    }
    +
    +    public interface TestReader {
    +        void read(InputArchive ia) throws IOException;
    +    }
    +
    +    void checkWriterAndReader(TestWriter writer, TestReader reader) {
    +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    +        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
    +        try {
    +            writer.write(oa);
    +        } catch (IOException e) {
    +            Assert.fail("Should not throw IOException");
    +        }
    +        InputStream is = new ByteArrayInputStream(baos.toByteArray());
    +        BinaryInputArchive ia = BinaryInputArchive.getArchive(is);
    +        try {
    +            reader.read(ia);
    +        } catch (IOException e) {
    +            Assert.fail("Should not throw IOException while reading back");
    +        }
    +    }
    +
    +    @Test
    +    public void testWriteInt() {
    +        final int expected = 4;
    +        final String tag = "tag1";
    +        checkWriterAndReader(
    +                new TestWriter() {
    --- End diff --
    
    Can we use lambdas?


---

Reply via email to