KVSerializer implements IKVSerializer { @Override public int deserializeKV(DataInputStream in, SizedWritable<?> key, SizedWritable<?> value) throws IOException { if (!in.hasUnReadData()) { return 0; } key.length = in.readInt(); value.length = in.readInt(); keySerializer.deserialize(in, key.length, key.v); valueSerializer.deserialize(in, value.length, value.v); return key.length + value.length + KV_HEAD_LENGTH; } KVSerializer(Class<K> kclass, Class<V> vclass); @Override void updateLength(SizedWritable<?> key, SizedWritable<?> value); @Override int serializeKV(DataOutputStream out, SizedWritable<?> key, SizedWritable<?> value); @Override int serializePartitionKV(DataOutputStream out, int partitionId,
      SizedWritable<?> key, SizedWritable<?> value); @Override int deserializeKV(DataInputStream in, SizedWritable<?> key,
      SizedWritable<?> value); static final int KV_HEAD_LENGTH; }
@Test public void testDeserializer() throws IOException { final DataInputStream in = Mockito.mock(DataInputStream.class); Mockito.when(in.hasUnReadData()).thenReturn(true); Assert.assertTrue(serializer.deserializeKV(in, key, value) > 0); Mockito.verify(in, Mockito.times(4)).readInt(); Mockito.verify(in, Mockito.times(2)).readFully(Matchers.any(byte[].class), Matchers.anyInt(), Matchers.anyInt()); }