CachedObjectParser extends Parser<CachedObject> { @Override public CachedObject parse() { if (connectionEndType == ConnectionEndType.CLIENT) { cachedObject.setCachedInformationType(parseByteField(ExtensionByteLength.CACHED_INFO_TYPE)); cachedObject.setHashValueLength(parseIntField(ExtensionByteLength.CACHED_INFO_HASH_LENGTH)); cachedObject.setHashValue(parseByteArrayField(cachedObject.getHashValueLength().getValue())); } else { cachedObject.setCachedInformationType(parseByteField(ExtensionByteLength.CACHED_INFO_TYPE)); cachedObject.setHashValue((ModifiableByteArray) null); cachedObject.setHashValueLength((ModifiableInteger) null); } return cachedObject; } CachedObjectParser(int startposition, byte[] array, ConnectionEndType connectionEndType); @Override CachedObject parse();  }
@Test public void parse() { CachedObjectParser parser = new CachedObjectParser(0, cachedObjectBytes, speakingEndType); CachedObject cachedObject = parser.parse(); assertEquals(infoType.getValue(), (long) cachedObject.getCachedInformationType().getValue()); if (hashLength != null) { assertEquals(hashLength, cachedObject.getHashValueLength().getValue()); } else { assertNull(cachedObject.getHashValueLength()); } if (hash != null) { assertArrayEquals(hash, cachedObject.getHashValue().getValue()); } else { assertNull(cachedObject.getHashValue()); } }