title: Compare all properties in two objects of different classes in unit test
body: <p>I have some objects (of different class) say PersonType1 and PersonType2 and trying to compare the fields are equal in the test case. The scenario is like:</p>
  
  <pre><code>jsonA -&gt; PersonTypeA;
  jsonB -&gt; PersonTypeB;
  </code></pre>
  
  <p>both PersonTypeA.class and PersonTypeB.class have the same properties, say id, name, etc.</p>
  
  <p>I am trying to assert the values are equal like this:</p>
  
  <pre><code>assertEquals(personA.getId(), personB.getId());
  </code></pre>
  
  <p>I am not able to use standard reflection equals provided by Mockito as the classes are not same.
  I am not planning a write a bunch of extra code to compare the obejcts. Something more in the line of:</p>
  
  <pre><code>Assert.assertTrue(new ReflectionEquals(expected, excludeFields).matches(actual)); //mockito
  </code></pre>
  
  <p>to</p>
  
  <pre><code>Assert.assertTrue(compareProperties(expected, excludeFields).matches(actual));
  </code></pre>
  
  <p>Edit 1: <strong>This is not a duplicate question</strong>
  I am trying to compare <strong>2 different objects of different classes</strong> if they have the same value in properties which have the same name. I can write the code but looking for some existing util methods if already present in junit5, mockito, hamcrest, etc</p>
  
  <pre><code>assertEquals(objA.getId(), objB.getId());
  //like this there are 30 properties
  </code></pre>
  
  <p>also there are nested objects like list, set of Strings. Comparing them manually is too much pain</p>
  
  <p>Edit 2: Maybe this will explain better</p>
  
  <p>I do not have control on the POJOs. They are owned by someone else. So, essentially if I have 2 classes </p>
  
  <pre><code>class Cat{
    String id;
    String name;
    // 30 more properties
  }
  
  class Dog{
    String id;
    String name;
   // 30 more properties
  }
  </code></pre>
  
  <p>How to compare cat and dog have same values in id, name, etc. Because there are so many properties I do not want to write</p>
  
  <pre><code>assertEquals(cat.getId(), dog.getId());
  </code></pre>
  
  <p>So, is there any utility to do that? We can do the other way round, if we have 2 objects (of different classes) we can copy the properties using <code>BeanUtils.copyProperies(o1, o2)</code> in Spring and apache bean utils. Similarly is there a way to compare the properties?</p>