title: Mockito says arguments are not identical but they are?
body: <p>This is the method that I want to test:</p>
  
  <pre><code>public class SelectionVariantUniqueConstraintValidatorImpl implements UniqueConstraintValidator {
  
      private SessionFactory sessionFactory;
  
      @Override
      public List&lt;Criteria&gt; buildValidationCriteria(Object entity, Serializable id, String[] propertyNames) {
          final SelectionVariant selectionVariant = (SelectionVariant) entity;
          final Session session = sessionFactory.getCurrentSession();
          final Criteria criteria = session.createCriteria(SelectionVariant.class);
          criteria.add(Restrictions.eq("client", selectionVariant.getClient()));
          criteria.add(Restrictions.eq("variant.variantName", selectionVariant.getVariant().getVariantName()));
  
          return new ArrayList&lt;Criteria&gt;(Arrays.asList(criteria));
      }
  
      @Required
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  }
  </code></pre>
  
  <p>And this is my test:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class SelectionVariantUniqueConstraintValidatorImplTest {
  
      SelectionVariantUniqueConstraintValidatorImpl selectionVariantUniqueConstraintValidator
              = new SelectionVariantUniqueConstraintValidatorImpl();
  
      @Mock
      private SessionFactory sessionFactory;
      @Mock
      private Session session;
      @Mock
      private Criteria criteria;
  
      @Before
      public void setUp() throws Exception {
          selectionVariantUniqueConstraintValidator.setSessionFactory(sessionFactory);
      }
  
      @Test
      public void testBuildValidationCriteria() throws Exception {
          Mockito.when(sessionFactory.getCurrentSession()).thenReturn(session);
          Mockito.when(session.createCriteria(SelectionVariant.class)).thenReturn(criteria);
          SelectionVariant selectionVariant = new SelectionVariant();
          Client client = new ClientBuilder().businessKey("HPD").description("desc").version(0).id(1L).build();
          selectionVariant.setClient(client);
          selectionVariantUniqueConstraintValidator.buildValidationCriteria(selectionVariant, null, null);
          Mockito.verify(criteria,Mockito.atLeastOnce()).add(Restrictions.eq("client", selectionVariant.getClient()));
      }
  }
  </code></pre>
  
  <p>And this is what I see in the console:</p>
  
  <pre><code>Argument(s) are different! Wanted:
  criteria.add(
      client=Client{id=1, businessKey='HPD', description='desc', version=0}
  );
  -&gt; at com.innflow.ebtam.dao.hibernate.variant.SelectionVariantUniqueConstraintValidatorImplTest.testBuildValidationCriteria(SelectionVariantUniqueConstraintValidatorImplTest.java:48)
  Actual invocation has different arguments:
  criteria.add(
      client=Client{id=1, businessKey='HPD', description='desc', version=0}
  );
  -&gt; at com.innflow.ebtam.dao.hibernate.variant.SelectionVariantUniqueConstraintValidatorImpl.buildValidationCriteria(SelectionVariantUniqueConstraintValidatorImpl.java:36)
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Edit:</p>
  
  <p>equals method in Client.java is as follows:</p>
  
  <pre><code>@Override
  public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || (getClass() != o.getClass() &amp;&amp; !(o instanceof Client))) return false;
  
      Client client = (Client) o;
  
      if (businessKey != null ? !businessKey.equals(client.getBusinessKey()) : client.getBusinessKey() != null)
          return false;
  
      return true;
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>hashCode method in Client.java : </p>
  
  <pre><code>@Override
  public int hashCode() {
      return businessKey != null ? businessKey.hashCode() : 0;
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>This makes the test work:</p>
  
  <pre><code>Mockito.verify(criteria,Mockito.atLeastOnce()).add(Restrictions.eq("client", Mockito.any(Client.class)));
  </code></pre>