• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Mocking a ReST web service

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an issue in mocking my rest web service's, one of the private methods.

So the flow, goes something like this,

JobController --> JobService --> createJob()

So here, in createJob() of my JobService, I will do another rest call to create a job, because job creation is hosted by someother team and I want to use the API exposed by them.
Before making a call to the API, I will create my payload, by calling prepareJobEntity(), which is a private method.




So, in my test case, this is the way I am trying to mock.



My TestDataProvider looks something like this.



The issue I am facing is,
Argument(s) are different! Wanted:
schedulerManager.create(
   com.scheduler.client.entity.Job@4a1a412e
);
-> at com.JobControllerTest.testCreateJob_whenJobDoesNotExist(JobControllerTest.java:90)
Actual invocation has different arguments:
schedulerManager.create(
   com.entity.Job@c568f91
);
-> at com.JobService.createProcessingJob(JobService.java:61)

I understand both the job instances are different, and that is the reason I am getting this issue. But, kind of confused on how to solve this. Can anyone please throw some light on this?
 
Ashwin Ganesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the way, I am trying to mock in my test, is in a wrong way?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's happening is that your Job class does not have an equals method, so it is using the default one from Object.
Since the Job you create in the test and the Job created in the code are not the same object then the mock check for 'schedulerManager.create(job)' will fail as the two jobs are not equal.

So, give Job a meaningful equals method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic