Results 1 to 5 of 5
  1. #1
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default assertTrue not working

    I have the following test case, but it's not working even though the values do match up. Anyone know what's going on?

    Java Code:
    try {
    			String str = InfixToPostfixParens.convert("(6 + 6) * 2");
    			System.out.println(str);
    			assertTrue(str == "6 6 + 2 * ");
    		} catch (InfixToPostfixParens.SyntaxErrorException e) {
    			e.printStackTrace(); 
    		}
    The output I get from the print statement is
    Java Code:
    6 6 + 2 *
    Which matches what I have in my assertTrue...
    Last edited by kraigballa; 03-23-2012 at 09:39 PM.

  2. #2
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: assertTrue not working

    The space after the asterisk is there in the str print

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default Re: assertTrue not working

    Conratulations! You're the kazillionth person trying to compare two Strings for equality with the == operator; it doesn't work; read the API documentation for the equals( ... ) method in the String class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: assertTrue not working

    ARG!!!! I'm used to PHP not Java quite yet. Both should work in all reality though...

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default Re: assertTrue not working

    Quote Originally Posted by kraigballa View Post
    ARG!!!! I'm used to PHP not Java quite yet. Both should work in all reality though...
    Why do you think 'both should work'? The way to compare two Strings for equality in Java is using the equals( ... ) method, no matter how much you wish it to be otherwise.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Collisions are working & not working
    By Jayayoh in forum Java 2D
    Replies: 1
    Last Post: 06-24-2011, 05:21 PM
  2. Why isn't this working?
    By nickburris in forum New To Java
    Replies: 14
    Last Post: 02-03-2011, 02:00 AM
  3. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  4. working with JC
    By yuhobebbho in forum New To Java
    Replies: 0
    Last Post: 02-10-2010, 11:22 PM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 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
  •