1

i have created an assertion line as below

String title = "A"; int year = 2009; String director = "Zebra"; 

VideoObj a = new VideoObj(title, year, director);

Assert.assertFalse(a.equals(new VideoObj(title+"1", year,director))); 

why does this fail?? the equal method is below.

public boolean equals(Object thatObject) { if (!(thatObject instanceof VideoObj)) return false; VideoObj that = (VideoObj) thatObject; return ((_title.equals(that.title())) && (_director.equals(that.director())) && (_year == that.year())); } 

but the below statement

Assert.assertFalse(a.equals(new VideoObj(title, year, director + "1"))); 

does not fail? can some one explain why the first assert statement fail and not the second?

5
  • 1
    Please show a short but complete program demonstrating your problem. In particular, that's a bizarre equality method. Commented Jan 29, 2012 at 19:53
  • Your equals method is very wrong. Commented Jan 29, 2012 at 19:53
  • this is what i got from my professor Commented Jan 29, 2012 at 19:55
  • Does the predicate still fail to deliver the expected result after correcting the change to &&? And why is the year not germane to equivalence? Commented Jan 29, 2012 at 20:34
  • it works now, but y didn't it go through if it were a ||???? Commented Jan 29, 2012 at 21:38

2 Answers 2

1

You probably meant to use && instead of || in:

 return ((_title.equals(that.title())) || (_director.equals(that.director())) || (_year == that.year())); 

Otherwise you're checking that any of title, director or year are the same, not that all of them are.

Sign up to request clarification or add additional context in comments.

Comments

1

Shouldn't it rather be ((_title.equals(that.title())) && (_director.equals(that.director())) && (_year == that.year()))

Two videos are equal if title AND year AND director is equal, not when only 1 of them is...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.