title: Why do we not mock domain objects in unit tests?
body: <p>I give you 2 tests; the purpose of which is <strong>solely</strong> to confirm that when <code>service.doSomething</code> is called, <code>emailService.sendEmail</code> is called with the person's email as a parameter.</p>
  
  <pre><code>@Mock 
  private EmailService emailService;
  
  @InjectMocks
  private Service service;
  
  @Captor
  private ArgumentCaptor&lt;String&gt; stringCaptor;
  
  @Test
  public void test_that_when_doSomething_is_called_sendEmail_is_called_NO_MOCKING() {
  
      final String email = "billy.tyne@myspace.com";
  
      // There is only one way of building an Address and it requires all these fields
      final Address crowsNest = new Address("334", "Main Street", "Gloucester", "MA", "01930", "USA");
      // There is only one way of building a Phone and it requires all these fields
      final Phone phone = new Phone("1", "978-281-2965");
      // There is only one way of building a Vessel and it requires all these fields
      final Vessel andreaGail = new Vessel("Andrea Gail", "Fishing", 92000);
      // There is only one way of building a Person and it requires all these fields
      final Person captain = new Person("Billy", "Tyne", email, crowsNest, phone, andreaGail);
  
      service.doSomething(captain); // &lt;-- This requires only the person's email to be initialised, it doesn't care about anything else
  
      verify(emailService, times(1)).sendEmail(stringCaptor.capture());
  
      assertThat(stringCaptor.getValue(), eq(email));   
  }
  
  @Test
  public void test_that_when_doSomething_is_called_sendEmail_is_called_WITH_MOCKING() {
  
      final String email = "billy.tyne@myspace.com";
  
      final Person captain = mock(Person.class);
      when(captain.getEmail()).thenReturn(email);
  
      service.doSomething(captain); // &lt;-- This requires the person's email to be initialised, it doesn't care about anything else
  
      verify(emailService, times(1)).sendEmail(stringCaptor.capture());   
  
      assertThat(stringCaptor.getValue(), eq(email));   
  }
  </code></pre>
  
  <p>Why is it that my team is telling me not to mock the domain objects required to run my tests, but not part of the actual test? I am told mocks are for the dependencies of the tested service only. In my opinion, the resulting test code is leaner, cleaner and easier to understand. There is nothing to distract from the purpose of the test which is to verify the call to <code>emailService.sendEmail</code> occurs. This is something that I have heard and accepted as gospel for a long time, over many jobs. But I still can not agree with.</p>