public static <T> void testByteCount(Coder<T> coder, Coder.Context context, T[] elements)
throws Exception {
TestElementByteSizeObserver observer = new TestElementByteSizeObserver();
try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) {
for (T elem : elements) {
coder.registerByteSizeObserver(elem, observer);
coder.encode(elem, os, context);
observer.advance();
}
long expectedLength = os.getCount();
if (!context.isWholeStream) {
assertEquals(expectedLength, observer.getSum());
}
assertEquals(elements.length, observer.getCount());
}
}