assertSame(Object expect, Object actual)
and
assertEquals(Object expect, Object actual)
What is/are the difference(s)?
Interesting, there is
assertNotSame(Object expect, Object actual)
But there is no
assertNotEquals(Object expect, Object actual)
presumable the first checks
expect == actual
and the second checks
expect..equals(actual).
or possibly
expect == null ? actual == null : expect..equals(actual).
StringBuilder s1 = new StringBuilder("abc");
StringBuilder s2 = new StringBuilder("abc");
// Why this tells me they are NOT the same?
Assert.assertSame(s1.toString(), s2.toString());
// Why this tells me they are equals?
Assert.assertEquals(s1.toString(), s2.toString());
They are different objects, but they have the same value. If that's
not enough of an explanation, you need to find a good beginning
tutorial on Java's object model.
To rephrase, because
s1.toString() != s2.toString()
but
s1.toString().equals( s2.toString() )
--
Lew
Put a dollar in your left pocket, and a dollar in your right.
Now answer two questions:
1) Is the value in your left pocket equal to the value in
your right pocket?
2) Are your left pocket and your right pocket the same
pocket?
(If your answer to [2] is "Yes," it follows that you have only
one dollar and should send me the other one :-)
Maybe assertSame should have been called assertSameObject.
It would have made the meaning of it more obvious.
Arne
Perhaps it would have, but I don't see it. How about 'assertIsSame()'? This
extends the convention that "isX" expresses a boolean condition "X", and
avoids the noise-word "Object" in the method name.
Thought experiment only, since no one will change it for our convenience.
--
Lew
f-u set to clj.programmer
I do wonder from time to time why people bother to write documentation.
This whole thread probably would have been avoided by looking at the
JUnit JavaDocs and / or experimenting a bit.
Just my 0.02 EUR...
robert