This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Testing and the fly likes Better way to test Message Digested String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Better way to test Message Digested String" Watch "Better way to test Message Digested String" New topic
Author

Better way to test Message Digested String

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

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.


Regards
KumarRaja

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

I agree with you.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Better way to test Message Digested String
 
Similar Threads
JUnit tests for Getters and Setters
unable to find error in the code?
doubt about equals vs ==
The " == " sign is confusing....
comparing Strings