title: Mocking a non-abstract method of an abstract class
body: <p>I am trying to unit-test a class that extends an abstract base <code>class</code>.
  Here are the "similar classes" for illustration purposes:</p>
  
  <pre><code>public abstract class MyAbstractBaseClass {
    @Autowired
    private WaterFilter waterFilter;
  
    protected List&lt;String&gt; filterComponents(List&lt;String&gt; allComponents) {
      return waterFilter.filter(allComponents);
    }
  }
  
  public class MyDerivedClass extends MyAbstractBaseClass {
    public List&lt;String&gt; filterWater(List&lt;String&gt; allWaterComponents) {
      List&lt;String&gt; filteredComponents = this.filterComponents(allWaterComponents); //calls abstract class's filterComponets()
      filteredComponents.add("something-else");
      return filteredComponents;
    }
  }
  </code></pre>
  
  <p>Here is the unit test I am trying:</p>
  
  <pre><code>    @RunWith(EasyMockRunner.class)
      public class MyDerivedClassTest {
          @TestSubject
          private MyDerivedClassTest SUT;
  
          @Before
          public void setup() {
             SUT = new MyDerivedClassTest();
          }
  
          @Test
          public void test filterWater_HappyCase() {
             //I want to mock my abstract class's filterComponents() method
             //I am trying this:
             EasyMock.expect(SUT.filterComponents(getDummyComponents())).andReturn(getSomeComponents());
  
            //What to replay here?
            //EasyMock.replay(...)
  
            List&lt;String&gt; actualResult = SUT.filterWater(getDummyComponents());
  
            //assert something
            //What to verify?
            //EasyMock.verify(...)
      }
  }
  </code></pre>
  
  <p>When I run this test, I get </p>
  
  <blockquote>
    <p>java.lang.NullPointerException</p>
  </blockquote>
  
  <p>in <code>MyAbstractBaseClass.filter(allComponents)</code> </p>
  
  <p>I understand that the autowired "waterFilter" is not getting initialized. But then, I just want to mock the "non-abstract" method of the abstract <code>class</code> in my unit test. </p>
  
  <p>How should I go about this using EasyMock? Also, I don't know what to <code>replay()</code> and <code>verify()</code>. </p>