BoundBufferCodecFactory implements CodecFactory { public <T> Codec<T> create(AnnotatedElement metadata, Class<T> type, ResolverContext context) { if (type.isArray() && BYTE_CLASS.equals(type) && metadata.isAnnotationPresent(BoundBuffer.class)) { return (Codec<T>) new BoundBufferCodec(metadata.getAnnotation( BoundBuffer.class).match()); } else { return null; } }  Codec<T> create(AnnotatedElement metadata, Class<T> type,
                               ResolverContext context);  }
@Test public void encodedBufferShouldEqualMatchBuffer() throws IOException { byte[] match = { 1, 2, 3, 4 }; when(metadata.isAnnotationPresent(BoundBuffer.class)).thenReturn(true); when(metadata.getAnnotation(BoundBuffer.class)).thenReturn(boundBuffer); when(boundBuffer.match()).thenReturn(match); Codec<byte[]> codec = factory.create(metadata, byte[].class, null); ByteArrayOutputStream out = new ByteArrayOutputStream(); codec.encode(match, new OutputStreamBitChannel(out), null); byte[] output = out.toByteArray(); assertThat(output.length, is(match.length)); assertArrayEquals(match, output); }