title: How to unit-test a presenter in a MVP
body: <p>I have a model view presenter triad. I'd like to know what's the usual way to test the presenter.</p>
  
  <p>The first thing that came to my mind was to instantiate the presenter and instantiate a real view and then assert that the view would accomplish the expected behavior.</p>
  
  <pre><code>public void itShouldSayHello() {
      View view = new View();
      Presenter presenter = new Presenter(view);
      presenter.userSaid("hello");
      assertTrue(view.getGreeting().equals("hello"));
  }
  </code></pre>
  
  <p>Then I thought that the view was not under test and so I created a fake view.</p>
  
  <pre><code>private String greeting;
  
  public void itShouldSayHello() {
      View view = new FakeView();
      Presenter presenter = new Presenter(view);
      presenter.userSaid("hello");
      assertTrue(greeting.equals("hello"));
  }
  private class FakeView implements View {
      @Override
      public void displayGreeting(String saluto) {
          greeting = saluto;
      }
  }
  </code></pre>
  
  <p>Then I thought that the interface of the view could change. This would've made the code harder to maintain. So I wrote the test and asserted that something was to be presented to the view. This way even if the interface changed I would have to change one line of code in the tests.</p>
  
  <pre><code>public void itShouldSayHello() {
      View view = mock(View.class);
      Presenter presenter = new Presenter(view);
      presenter.userSaid("hello");
      verify(view).displayGreeting("hello");
  }
  </code></pre>
  
  <p>So basically what I test now is that I expect the presenter to gather and process some information and finally pass it to the view, then I verify that the passed values are correct.</p>
  
  <p>So I guess I'm not using a fake now, I'm using a mock and then I verify if the mock receives the correct values.</p>
  
  <p>Another problem I have is with the model. But I think this is insurmountable. What I have to do to see if the presenter behaves correctly is to create a big fat fixture. Then a pass all the various combinations and see if the presenter behaves correctly.</p>
  
  <p>How do you test your presenter?</p>