SlicingCodec implements Codec<T> { public void encode(T value, BitChannel channel, Resolver resolver) throws IOException { wrapped.encode(value, new BoundedBitChannel(channel, sizeExpr.eval(resolver)), resolver); } SlicingCodec(Codec<T> wrapped, Expression<Integer, Resolver> sizeExpr); T decode(BitBuffer buffer, Resolver resolver, Builder builder); void encode(T value, BitChannel channel, Resolver resolver); Class<?>[] getTypes(); Expression<Integer, Resolver> getSize(); Class<?> getType(); CodecDescriptor getCodecDescriptor();  }
@Test public void testEncoding() throws IOException { SlicingCodec<String> codec = new SlicingCodec(wrapped, sizeExpr); when(sizeExpr.eval(resolver)).thenReturn(3); codec.encode("DONE", channel, resolver); ArgumentCaptor<BitChannel> bitChannelCaptor = ArgumentCaptor.forClass(BitChannel.class); verify(wrapped).encode(eq("DONE"), bitChannelCaptor.capture(), eq(resolver)); verify(sizeExpr).eval(resolver); assertThat(bitChannelCaptor.getValue(), instanceOf(BoundedBitChannel.class)); verifyNoMoreInteractions(wrapped, sizeExpr, resolver); }