testing equals() using Mockito ?

15 views
Skip to first unread message

Ashok Shanmugam

unread,
Sep 11, 2015, 4:50:11 AM9/11/15
to mockito
How to test Model class equals() method. Getting following issue.

 <<< FAILURE! - in EmployeeTest
testEquals(EmployeeTest)  Time elapsed: <<< ERROR!
org.mockito.exceptions.misusing.UnfinishedVerificationException: 
Missing method call for verify(mock) here:
-> at EmployeeTest.testEquals(EmployeeTest.java:20)

Example of correct verification:
    verify(mock).doSomething()

Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.


---------------------------------------------------------------------------------------


private static Employee mockedEmployee;
private static Employee employee;



@BeforeClass
public static void setup() {
    mockedEmployee = mock(Employee.class);
    employee = new Employee("first", "last");

   when(mockedEmployee .getFirstName()).thenReturn(Employee.getFirstName());

}


@Test
public void testEquals() {
    Mockito.verify(mockedEmployee).equals(employee);
}
Reply all
Reply to author
Forward
0 new messages