SlicingCodec implements Codec<T> { public T decode(BitBuffer buffer, Resolver resolver, Builder builder) throws DecodingException { BitBuffer slice = buffer .slice(sizeExpr.eval(resolver)); return wrapped.decode(slice, resolver, builder); } 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 testDecoding() throws DecodingException { SlicingCodec<String> codec = new SlicingCodec(wrapped, sizeExpr); when(sizeExpr.eval(resolver)).thenReturn(13); when(buffer.slice(Mockito.anyInt())).thenReturn(slice); when(wrapped.decode(any(BitBuffer.class), any(Resolver.class), any(Builder.class))).thenReturn("DONE"); assertThat(codec.decode(buffer, resolver, builder), is("DONE")); verify(sizeExpr).eval(resolver); verify(buffer).slice(13); verify(wrapped).decode(slice, resolver, builder); verifyNoMoreInteractions(wrapped, sizeExpr, builder, buffer, slice, resolver); }