Cryptography { public static final String calculateCheckSum(final String strData) throws NoSuchAlgorithmException{ MessageDigest messageDigest; messageDigest = MessageDigest.getInstance(ALGORITHM); messageDigest.reset(); messageDigest.update(strData.getBytes(), 0, strData.length()); return codHex(messageDigest.digest()); }  static final String calculateCheckSum(final String strData);  }
@Test public void calculateCheckSum() throws Exception{ final String HEXES = "0123456789ABCDEF"; final String ALGORITHM = "SHA-512"; int sizeBuffer = 100; byte[] bDigest=new byte[sizeBuffer]; PowerMockito.mockStatic(MessageDigest.class); PowerMockito.when(MessageDigest.getInstance(ALGORITHM)).thenReturn(messageDigest); Mockito.when(messageDigest.digest()).thenReturn(bDigest); PowerMockito.whenNew(StringBuffer.class).withArguments(sizeBuffer).thenReturn(hex); Mockito.when(hex.append(HEXES.charAt((bDigest[0] & 0xF0) >> 4))).thenReturn(hex); Mockito.when(hex.append(HEXES.charAt((bDigest[0] & 0x0F)))).thenReturn(hex); Mockito.when(hex.toString()).thenReturn(strChkSum); Cryptography.calculateCheckSum(strData); }