title: Proper way of using and testing generated mapper
body: <p>Recently we encountered some conflict during the development of our system. We discovered, that we have 3 different approaches to testing in our team, and we need to decide which one is best and check if there is nothing better than this.</p>
  
  <p>First, let's face some facts:<br>
   - we have 3 data layers in the system (DTOs, domain objects, tables)<br>
   - we are using mappers generated with mapstruct to map objects of each layer to another<br>
   - we are using mockito<br>
   - we are unit-testing each of our layers<br></p>
  
  <p>Now the conflict: Let's assume that we want to test <code>ExampleService</code> which is using <code>ExampleModelMapper</code> to map <code>ExampleModel</code> to <code>ExampleModelDto</code> and doing some additional business logic which needs testing. We can verify the correctness of returned data in three different ways:</p>
  
  <p>a) We can manually compare each field of a returned object to an expected result:<br></p>
  
  <pre><code>assertThat(returnedDto)
                  .isNotNull()
                  .hasFieldOrPropertyWithValue("id", expectedEntity.getId())
                  .hasFieldOrPropertyWithValue("address", expectedEntity.getAddress())
                  .hasFieldOrPropertyWithValue("orderId", expectedEntity.getOrderId())
                  .hasFieldOrPropertyWithValue("creationTimestamp", expectedEntity.getCreationTimestamp())
                  .hasFieldOrPropertyWithValue("price", expectedEntity.getPrice())
                  .hasFieldOrPropertyWithValue("successCallbackUrl", expectedEntity.getSuccessCallbackUrl())
                  .hasFieldOrPropertyWithValue("failureCallbackUrl", expectedEntity.getFailureCallbackUrl())
  </code></pre>
  
  <p>b) We can use real mapper (same as in normal logic) to compare two objects:<br></p>
  
  <pre><code>assertThat(returnedDto).isEqualToComparingFieldByFieldRecursivly(mapper.mapToDto(expectedEntity)))
  </code></pre>
  
  <p>c) And finally, we can mock mapper and its response:</p>
  
  <pre><code>final Entity entity = randomEntity();
  final Dto dto = new Dto(entity.getId(), entity.getName(), entity.getOtherField());
  when(mapper.mapToDto(entity)).thenReturn(dto);
  </code></pre>
  
  <p>We want to make tests as good as possible while keeping them elastic and change-resistant. We also want to keep to DRY principle.</p>
  
  <p>We are happy to hear any pieces of advice, comments, pros, and cons of each method. We are also open to see any other solutions.</p>
  
  <p>Greetings.</p>