• What is/are the difference(s) between assertSame and assertEquals i

    From anvesh.boddupalli@securifi.com@21:1/5 to All on Fri Apr 28 07:04:33 2017
    I have a similar problem

    Genericindex a;
    Genericindex b;

    a= datafrommethod();//returns object of Genericindex
    b= datafrommethod();//returns object of Genericindex

    b= anothermethod(b);//some object might be overriden

    if(notoverridden){
    assertEquals(a,b);}// this fails

    can someone explain this?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eric Sosman@21:1/5 to anvesh.boddupalli@securifi.com on Fri Apr 28 11:03:34 2017
    On 4/28/2017 10:04 AM, anvesh.boddupalli@securifi.com wrote:
    I have a similar problem

    Genericindex a;
    Genericindex b;

    a= datafrommethod();//returns object of Genericindex
    b= datafrommethod();//returns object of Genericindex

    b= anothermethod(b);//some object might be overriden

    if(notoverridden){
    assertEquals(a,b);}// this fails

    can someone explain this?

    There's not enough information for a full explanation -- in
    particular, we don't know what datafrommethod() does, nor what
    anothermethod() does. However, if the assertEquals() reports a
    failure, what we *do* know is

    1) At least one of `a' and `b' is non-null, because if both
    were null assertEquals() would not fail. (It considers two
    null references to be "equal.")

    2) If `a' is null then `b' is non-null. Similarly, if `b'
    is null then `a' is non-null. Either way, `a' and `b' are
    unequal: One points to an object, and the other is null.

    3) If both `a' and `b' are non-null, then they point to
    two objects that are not equal according to the equals() method.
    This might be the equals() method of GenericIndex itself, or of
    a subclass of GenericIndex (if `a' or `b' points to a subclass
    instance), or an equals() method that GenericIndex inherits
    from one of its superclasses (perhaps java.lang.Object).

    ... and that's really all I can discern from what you've
    provided. If I knew more about about datafrommethod(), about
    anothermethod(), and about GenericIndex and its sub- and
    super-classes, I might be able to explain more fully.

    --
    esosman@comcast-dot-net.invalid
    Thirteen hundred sixty-three days to go.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From onlyfullstackdev@gmail.com@21:1/5 to All on Thu Mar 21 04:58:20 2019
    assertEquals - It check the objects are equal or not based on the overridded equals() method of that class. So we can check the equality of object based on their state(compare the values of their instance variables).

    assertEquals() The assertEquals() method compares two objects for equality, using their equals() method.

    @Test
    public void assertEquals_example() {
    Employee employeeNew = new Employee();
    employee.setSalary(1000000.0);
    assertEquals("EMPLOYEE OBJECT", employee, employeeNew);
    }
    If the two objects are equal according to there implementation of their equals() method, the assertEquals() method will return normally. Otherwise, the assertEquals() method will throw an exception, and the test will stop there.

    assertSame() and assertNotSame() The assertSame() and assertNotSame() methods tests if two object references point to the same object or not. It is not enough that the two objects pointed to are equals according to their equals() methods. It must be
    exactly the same object pointed to.

    Here is a simple example:

    @Test
    public void assertSame_assertNoSame_example() {

    assertSame(employeeService.getEmployeeFromId(1), employeeService.getEmployeeFromId(1));
    assertNotSame(employee, employeeService.getEmployeeFromId(1)); // We will get null as response
    }
    You can follow below url to get more information: https://onlyfullstack.blogspot.com/2019/02/junit-assert-methods.html

    https://onlyfullstack.blogspot.com/2019/02/junit-tutorial.html


    On Thursday, August 7, 2008 at 1:53:11 AM UTC+8, RC wrote:
    In JUnit Assert class have

    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)