Reputation: 1214
I am facing a wired situation while doing an assertion. I am asserting the value inside each list (Lists are supposed to contain same value even though that are not List of same objects)
Here is my assertion code :
for (int i=0 ; i< rst.size(); i++)
{
Assert.assertSame(l.get(i).getName(),rst.get(i).getText());
Here is the response I am getting :
FAILED: srch("tsk", "http://frstmwarwebsrv2.orsyptst.com:9000/duobject? searchString=TSK&filtercheck=nameSWF&p.index=0&p.size=8")
java.lang.AssertionError: expected [TSK(ACE700J)(000)(ACE700JU00)(000)] but found [TSK(ACE700J)(000)(ACE700JU00)(000)]
}
I have changed the above as advised by I am still getting the same error :
Assert.assertSame ((l.get(i).getName().trim()), rst.get(i).getText().trim());
Upvotes: 1
Views: 842
Reputation: 8264
The methods getName()
and getText()
both return Strings, so (assuming your problem is only leading and trailing white space) all you need to do is add .trim()
, like so:
Assert.assertEquals(l.get(i).getName().trim(),rst.get(i).getText().trim());
It seems, also, that what you want to do is test that different objects in memory are meaningfully equal. This means you want to use assertEquals()
, not assertSame()
.
Upvotes: 1