zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolivelli <...@git.apache.org>
Subject [GitHub] zookeeper pull request #726: ZOOKEEPER-3205: o.a.jute test cases
Date Tue, 27 Nov 2018 19:07:59 GMT
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?


---

Mime
View raw message