• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TestCase Error Mokito

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am getting null value when comparing result. Below is my Test Case


Here is my method :



Error is :


Also in attached file there are dependent methods provided.
methods.txt.jpeg
[Thumbnail for methods.txt.jpeg]
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These lines are problematic


If you say when(cltMock.getSalesforceClientObject(client,mockMap,"yagyesh.mishra@intelligrape.com")) then the arguments you pass to the method must match by the equals method to what you are setting up in your when block. That means your Configuration class must have an equals method which returns true for the object you passed in the when clause and the object that is passed at runtime. The same with the SalesforceClient class.

Often you don't care about the exact instance passed to those arguments in pure unit tests (scope of test should be small anyway) so you will typically see others write this as


and

Note that the string parameter in this case needs to be wrapped in the eq function because mockito doesn't allow you to mix exact values and those defined using any.. in one method call.
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I have made the changes in test case. Still having same errors :


Test Case :

When i debugged, I found there are no props set in getConfigProps(cloudConfig) method and all are null.

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is not testable and you are not using Mockito properly.
If the method you are testing has
then you can't provide a mock SalesforceClient to it.
You either need to provide that to your method as a parameter or make it an instance variable then mock it and inject the mock using @InjectMocks or similar.
Also, what does your getConfigProps(cloudConfig) method do? In order for your mocked version to be called you again have to call it on an object that you are injecting as a mock.
 
reply
    Bookmark Topic Watch Topic
  • New Topic