Originally posted by Corey McGlone:
How do I test that one Hashtable is the same as the next? If I use assertEquals, as I did here, I get a failure because the equals method, as defined in Hashtable, checks for object equality by checking reference values. Obviously, the two Hashtable objects are distinct objects so this fails even though the two Hashtables contain the same data in the same structure (I verified this through the use of my debugger).
So, how can I verify that my test succeeded? Do I need to pull the various pieces out of my hashtables and verify them?
Also, what should I do about exceptions?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Also, what should I do about exceptions? As you can see, the method I'm testing can throw a FileNotFoundException or some other IOException. In order to compile this, I need to catch those exceptions.
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Originally posted by Corey McGlone:
Should I be doing something like this?
Originally posted by Corey McGlone:
It hit me last night, my Hashtable has a custom data object in it call DocTypeData. I had never overridden the equals() method for this data type so that is where my error was coming from. Because the two DocTypeData objects were distinct, the equals() method had been returning false.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Greg Ostravich - SCPJ2
EqualsTester on every class in the codebase providing a no-arg constructor? Would it even make sense?
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
I can't imagine how to automate it though.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|