/** * Main testing method that runs the test based on the passed test spec. * * @param testSpec Test-specific routines (providing encoding/decoding streams). * @throws IOException I/O exception. */ protected void test(TestSpec testSpec) throws IOException { byte[] entity = "Hello world!".getBytes(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream encoded = testSpec.getEncoded(baos); encoded.write(entity); encoded.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); byte[] result = new byte[entity.length]; InputStream decoded = testSpec.getDecoded(bais); int len = decoded.read(result); assertEquals(-1, decoded.read()); decoded.close(); assertEquals(entity.length, len); assertArrayEquals(entity, result); }