### Question:
AgentDataHolder { protected String getHash(T data) { String json = null; try { json = MAPPER.writeValueAsString(data); } catch (JsonProcessingException e) { throw new RuntimeException("Error during mapping message to calculate hash", e); } String generatedPassword = null; try { MessageDigest md = MessageDigest.getInstance("SHA-512"); md.update(salt.getBytes("UTF-8")); byte[] bytes = md.digest(json.getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); } generatedPassword = sb.toString(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { e.printStackTrace(); } return generatedPassword; }    }### Answer:
@Test public void testGetHashWithTimestamp() { AmbariEventPublisher ambariEventPublisher = createNiceMock(AmbariEventPublisher.class); AgentConfigsHolder agentConfigsHolder = new AgentConfigsHolder(ambariEventPublisher); AgentConfigsUpdateEvent event1 = new AgentConfigsUpdateEvent(null, null); event1.setHash("01"); event1.setTimestamp(1L); String eventHash1 = agentConfigsHolder.getHash(event1); AgentConfigsUpdateEvent event2 = new AgentConfigsUpdateEvent(null, null); event2.setHash("02"); event2.setTimestamp(1L); String eventHash2 = agentConfigsHolder.getHash(event2); AgentConfigsUpdateEvent event3 = new AgentConfigsUpdateEvent(null, null); event3.setHash("01"); event3.setTimestamp(2L); String eventHash3 = agentConfigsHolder.getHash(event3); AgentConfigsUpdateEvent event4 = new AgentConfigsUpdateEvent(null, null); event4.setHash("02"); event4.setTimestamp(2L); String eventHash4 = agentConfigsHolder.getHash(event4); AgentConfigsUpdateEvent event5 = new AgentConfigsUpdateEvent(null, MapUtils.EMPTY_SORTED_MAP); event5.setHash("01"); event5.setTimestamp(1L); String eventHash5 = agentConfigsHolder.getHash(event5); assertEquals(eventHash1, eventHash2); assertEquals(eventHash1, eventHash3); assertEquals(eventHash1, eventHash4); assertFalse(eventHash1.equals(eventHash5)); }
@Test public void testGetHash() { AmbariEventPublisher ambariEventPublisher = createNiceMock(AmbariEventPublisher.class); MetadataHolder metadataHolder = new MetadataHolder(ambariEventPublisher); MetadataUpdateEvent event1 = new MetadataUpdateEvent(null, null, null, UpdateEventType.CREATE); event1.setHash("01"); String eventHash1 = metadataHolder.getHash(event1); MetadataUpdateEvent event2 = new MetadataUpdateEvent(null, null, null, UpdateEventType.CREATE); event2.setHash("02"); String eventHash2 = metadataHolder.getHash(event2); MetadataUpdateEvent event3 = new MetadataUpdateEvent(null, null, null, UpdateEventType.UPDATE); event3.setHash("01"); String eventHash3 = metadataHolder.getHash(event3); assertEquals(eventHash1, eventHash2); assertFalse(eventHash1.equals(eventHash3)); }