Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Testing Model class equals() method using Mockito(Mockito)
Testing Model class equals() method using Mockito [message #1707974] Fri, 11 September 2015 07:01 Go to next message
Ashok Shan is currently offline Ashok ShanFriend
Messages: 4
Registered: August 2015
Junior Member
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.

Sample test method. Using Mockito.verify() for testing equals method.



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);
}
Re: Testing Model class equals() method using Mockito [message #1708289 is a reply to message #1707974] Tue, 15 September 2015 08:02 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Hi,

This forum is dedicated to Eclipse Scout... I am not sure to understand why you posted this question here.

I am not a Mockito expert, but as far as I know, your test to not make any sense to me. Here a snippet taken from the Mockito documentation:
 //mock creation
 List mockedList = Mockito.mock(List.class);
 
 //using mock object
 mockedList.add("one");
 mockedList.clear();
 
 //verification
 Mockito.verify(mockedList).add("one");
 Mockito.verify(mockedList).clear();


With Mockito.verify(..) you check that some methods were called during your test... From the error you got, you are not allowed to test that equals(..) was called.

You should:
* Ask your question on a relevant Forum or Mailing List (or on stackoverflow.com if you do not know where to post).
* Provide more information about the Employee class you are using.

Previous Topic:Datasource authentication RAP client
Next Topic:Scout context menu on ValueFields in RAP
Goto Forum:
  


Current Time: Fri Apr 26 06:56:28 GMT 2024

Powered by FUDForum. Page generated in 0.03166 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top