title: Not able to write Unit Tests for such methods
body: <p>I am trying to junit test a very simple method. Something like this:</p>
  
  <pre><code>private SomeCarFactory someCarFactory;
  private Predicate&lt;CarRequest&gt; isCarColorRed = carRequest -&gt; carRequest.getCarColor() == CarTypeEnum.RED;
  public List&lt;CarResponse&gt; post(Set&lt;CarRequest&gt; newCarsSet){
      // Filter the cars based on their car colors
      List&lt;CarResponse&gt; carResponseList = someCarFactory.getCarService(CarTypeEnum.RED).execute(filterCarsBasedOnCarType(newCarsSet, isCarColorRed));
      return carResponseList;
  }
  
  private Set&lt;CarRequest&gt; filterCarsBasedOnCarType(Set&lt;CarRequest&gt; newCarsSet, Predicate&lt;CarRequest&gt; predicate) {
      return newCarsSet.stream().filter(predicate).collect(Collectors.toSet());
  }
  </code></pre>
  
  <p>I am using Junit4 and Mockito frameworks. I mocked the class <code>SomeCarFactory</code> and the <code>CarService</code> class which the factory class returns.</p>
  
  <pre><code>Set&lt;CarRequest&gt; redCarSet = createTestRedCars();
  Set&lt;CarRequest&gt; blueCarSet = createTestBlueCars();
  Set&lt;CarRequest&gt; carRequestSet = new HashSet&lt;&gt;();
  carRequestSet.addAll(redCarSet);     
  carRequestSet.addAll(blueCarSet);
  Mockito.when(someCarFactory.getCarService(CarTypeEnum.RED)).thenReturn(carService);
  Mockito.when(carService.execute(redCarSet)).thenReturn(someRedCarResponse);
  </code></pre>
  
  <p>The above obviously doesn't work because the <code>redCarSet Object</code> used in above <code>when</code> is different from the object that is being created when the method <code>filterCarsBasedOnCarType</code> is being called.</p>
  
  <p>How do I unit test the <code>post</code> method ?</p>