HashUnmodifiedItemChecker extends ChunkListenerSupport implements UnmodifiedItemChecker<T>, InitializingBean { @Override public boolean check(T item) throws Exception { initPropertyDescriptors(item); String key = makeHashKey(item); String hashSource = makeHashSource(item); MessageDigest md = MessageDigest.getInstance(this.hashAlgorithm); String hashValue = Base64.getEncoder().encodeToString(md.digest(hashSource.getBytes())); String storedHashValue = hashRepository.getHashValue(key); if (log.isDebugEnabled()) { log.debug("\n\tHash Key: {}\n\tHash Source: {}\n\tHash Value: {}\n\tStored Hash Value: {}", key, hashSource, hashValue, storedHashValue); } boolean eq = hashValue.equals(storedHashValue); if (!eq) { long ts = new Date().getTime(); if (expiry > 0) { ts += expiry; } else { ts += 3153600000000L; } chunkItemHashes.add(new ItemHash(key, hashValue, new Date(ts))); } return eq; }  void setHashRepository(HashRepository hashRepository); void setHashAlgorithm(String algorithm); void setKeyPropertyNames(List<String> keyPropertyNames); void setIgnorePropertyNames(List<String> ignorePropertyNames); void setExpiry(int expiry); void setExpiry(int expiry, TimeUnit timeUnit); void setKeyPrefix(String keyPrefix); @Override void afterChunk(ChunkContext context); @Override boolean check(T item); @Override void afterPropertiesSet();  }
@Test public void check() throws Exception { HashUnmodifiedItemChecker<TestObj> checker = new HashUnmodifiedItemChecker<>(); checker.setHashRepository(hashRepository); checker.setKeyPropertyNames(Arrays.asList("name")); checker.setIgnorePropertyNames(Arrays.asList("randomVal", "randomVal2")); checker.afterPropertiesSet(); TestObj p1 = new TestObj(); p1.setId(1); p1.setName("YK"); p1.setAge(20); p1.setRandomVal(123); p1.setRandomVal2(678); TestObj p2 = new TestObj(); p2.setId(1); p2.setName("YK"); p2.setAge(20); p2.setRandomVal(345); p2.setRandomVal2(493); boolean p1UnModified = checker.check(p1); checker.afterChunk(null); boolean p2UnModified = checker.check(p2); checker.afterChunk(null); Assert.assertFalse("p1UnModified must be false", p1UnModified); Assert.assertTrue("p2UnModified must be true",p2UnModified); }