aspose file tools*
The moose likes Beginning Java and the fly likes assertEquals is wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "assertEquals is wrong?" Watch "assertEquals is wrong?" New topic
Author

assertEquals is wrong?

Luke Winter
Greenhorn

Joined: Aug 18, 2012
Posts: 5
Hello,

I find it hard to believe that assertEquals is wrong but I can't for the life of me tell the difference between these two outputs:

Expected:


Actual:


Trace:


In the compare window, no red is shown. I pasted actual and expected into separate textfiles, compared the difference with Eclipse and nothing was found. Other tests that compare output are passing, it is just this one. Help please?
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

The trace is showing you what was expected and what was actual, and it looks like the expected string has an extra linefeed in it. Both contain square brackets [] that I don't see in your sample outputs.
Luke Winter
Greenhorn

Joined: Aug 18, 2012
Posts: 5
Greg Charles wrote:The trace is showing you what was expected and what was actual, and it looks like the expected string has an extra linefeed in it. Both contain square brackets [] that I don't see in your sample outputs.


Thank-you for your reply Greg. I see that it is the case that the expected looks as if it requires another line, but looking at the expected string:



where LS is the System line separator, it does not require an additional line.

EDIT: even if I copy the actual output into the expected output, I still get a mismatch.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

Well, you could get the source code for whatever version of JUnit you're using, and step into it with a debugger to see what's going on. The source I'm looking at doesn't add square brackets, or even those triangular brackets. It also doesn't truncate the string and add an ellipsis as far as I can tell, so I don't think you're feeding it the strings you think you're feeding it.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10101
    
164

You could also try do a actual.equals(expected) yourself within the JUnit code to see what that returns. Then you'll know if it's something with the assertEquals that's causing this problem or if those 2 strings aren't really equal.

[My Blog] [JavaRanch Journal]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7781
    
  21

Luke Winter wrote:I find it hard to believe that assertEquals is wrong but I can't for the life of me tell the difference between these two outputs:
...
In the compare window, no red is shown. I pasted actual and expected into separate textfiles, compared the difference with Eclipse and nothing was found. Other tests that compare output are passing, it is just this one. Help please?

Have you thought about putting your directions in a Direction enum?

To be honest, I'm not quite sure what all these String comparisons are doing - the Strings themselves appear to be some sort of indicator of direction, but I'm still not sure exactly how. If you put them in an enum, you could add an asString() method (or override toString()) that returns the display String for a particular Direction.

Better still, you could then compare Directions rather than Strings.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assertEquals is wrong?