• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Better way to test Message Digested String

 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

We have a utility class, for which I'm trying to determine some meaningful test cases. This utility class is basically used to encode the given string value.

In brief,

A method in our utility class, uses a Message Digest using the algorithm "SHA-512", performs the digest on the byte array of the input String and then encodes the byte array using org.apache.commons.codec.binary.Hex and the resultant char[] array is converted back to String and returned.

For my tests, what I'm doing is as follows



Apart from this, I could not find any meaningful testcase. To be frank, I'm not even happy with this test case. I'm looking for more intelligent test case, where I wish to decode the encoded string and compare with the resultant with the original string. But I know that, we can not determine the value, given a hash, though I can decode the char array using Hex. So what can be done to make the tests robust.

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar,
What are you trying to test further? Presumably the Apache library is already tested. All you are doing is changing the format yourself. One test case I can think of is to check the encoding doesn't change - store the result of SHAS2.encode(str1) in a constant as the "golden master".

As an aside:


is better than

The former gives a clearer error message about what is different. With encoding this isn't a big deal. With other values, it is very helpful.
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic