Results 1 to 3 of 3
  1. #1
    staffan is offline Member
    Join Date
    Nov 2008
    Location
    Gothenburg
    Posts
    4
    Rep Power
    0

    Default ComparisonFailure on equal(to the eye) strings

    Hello!

    I have problems with trying to verify a string read from a text file.

    * I read in the entire text file and save it as a String (say myStringReadFromFile).
    * I manually copy the text from the the text file, and as the text is not so long I paste it into my assertEquals method and adjust it slightly to something like this:

    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
    + "<Event pointID=\"Alarms\" xmlns=\"ng:event\">\n"
    + "<Header>\n"
    + ...
    , myStringReadFromFile);

    Now the thing is I get a junit.framework.ComparisonFailure. Using Eclipse, I double click on the failure to open the "Result Comparison" window, but nothing differs the actual from the expected text!
    I copy the two text fields manually into two different text files and run a winmerge on them. They are identical..

    Any help on how to make things easier..? :)

    Thanks!
    Staffan

  2. #2
    azzaiel's Avatar
    azzaiel is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    try usng string buffer

    Stringbuffer sb = new Stringbugger

    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
    sb.append("<Event pointID=\"Alarms\" xmlns=\"ng:event\">");
    sb.append("<Header>");

    assertEqualls(sb.tostring,myStringReadFromFile);
    It's easy to write a code that computers can understand...
    ... the challenge is to write a code that humans can understand

  3. #3
    staffan is offline Member
    Join Date
    Nov 2008
    Location
    Gothenburg
    Posts
    4
    Rep Power
    0

    Default solved

    Thanks for your reply azzaiel!

    After some more trying (including your proposal..) I found out that what I needed instead of \n after each line was \r\n. (CR LF)

    Simple as that.. :)

    /Staffan

Similar Threads

  1. Replies: 0
    Last Post: 01-03-2009, 11:00 AM
  2. Problem using equal() method
    By ookie833 in forum New To Java
    Replies: 3
    Last Post: 11-18-2008, 06:19 AM
  3. Entering a while loop with a not equal to string
    By bri1547 in forum New To Java
    Replies: 9
    Last Post: 07-09-2008, 08:10 AM
  4. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 07:21 AM
  5. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •