title: How to mock a repository method no matter the parameters with mockito
body: <p>I'm using spring framework and testing with Junit and mockito.</p>
  <p>Right now I have a method in my service which is using a few objects I create in the test, let's call them configObject1 and configObject2, I send them to the method as a parameter, and then the method start making some calls to another repositories along those configuration objects, those repositories are mocked and work well, the method makes a List of &quot;CalculusResult&quot; from those queries/configObjects. After that I use a repository extending CRUDRepository and make a saveAll(). Then it should return an iterable with the entities, but for some reason after the saveAll method it returns an empty list.</p>
  <p>Test:</p>
  <pre><code>@Test
  ...
  configObject1 conf1 = new configObject1 (...);
  configObject2 conf2 = new configObject2 (...);
  Calculusresult calcRes = new CalculusResult(null,...,new java.sql.Date(system.currentTimeMilis()),...);
  List&lt;CalculusResult&gt; resList= new ArrayList&lt;CalculusResult&gt;();
  resList.add(calcRes);
  
  Calculusresult calcRes2 = new CalculusResult(1,...,new java.sql.Date(system.currentTimeMilis()),...);
  List&lt;CalculusResult&gt; resList2= new ArrayList&lt;CalculusResult&gt;();
  resList2.add(calcRes2);
  
  when(calculusResultRepository.saveAll(resList)).thenReturn(resList2);
  ...
  assertTrue(!response.isEmpty())
  </code></pre>
  <p>Method from the service:</p>
  <pre><code>...//The method is building the list of calculusResults
  resCalc.setDate(new java.sql.Date(system.currentTimeMilis()))
  resList.add(calcres);//CalculusResult object is added to the list, this object is well made
  List&lt;CalculusResult&gt; savedResults = (List&lt;CalculusResult&gt;) calculusResultRepository.saveAll(resList); //This returns an empty list (If I don't cast, it also returns nothing)
  
  for(CalculusResult calcres : savedResults){
  ... //This makes nothing because savedResults is empty, making the response empty and failing the test.
  </code></pre>
  <p>Repository:</p>
  <pre><code>@Repository
  public interface CalculusResultRepository extends CrudRepository&lt;CalculusResult, Long&gt; {
  
  }
  
  </code></pre>
  <p>I'm not sure but I think the problem may be that the object I'm creating in the test is different to the one in the service because one of the attributes is an sql Date of the moment it's created, so maybe it's not triggering &quot;when(calculusRepository.saveAll(reslist)...&quot; in the test because the object created in the test and the one created in the service have different Dates in that atribute.</p>
  <p>If that's the case, is there a way to fix it? Or is the problem a completely different thing?</p>