title: How can I test a method which invoke protected (unwanted) methods of parent class?
body: <p>I'm stuck in a very weird case.
  I have some specific code which I need to test.
   Here it is:</p>
  
  <pre><code>public class A {
  
      /*
       * The real method of real class is so big that I just don't want to test it.
       * That's why I use throwing an exception.
       */
      protected void method(Integer result) {
          throw new RuntimeException("Oops!");
      }
  
      protected &lt;T&gt; T generifiedMethod(String s, T type) {
          throw new RuntimeException("Oops!");
      }
  
      protected void mainMethod(Integer value) {
          throw new RuntimeException("Oops!");
      }
  }
  </code></pre>
  
  <p>I also have a child class:</p>
  
  <pre><code>public class B extends A {
  
      @Override
      protected void mainMethod(Integer value) {
          if (value == 100500) {
              Integer result = super.generifiedMethod("abc", 100);
              super.method(result);
          }
          super.mainMethod(value);
      }
  }
  </code></pre>
  
  <p>I need to cover the child class with tests.</p>
  
  <p>I was trying a lot of combinations with PowerMockito,
  but none of them can verify invocation of protected methods of parent class.
  Also, I have a restriction on use only Mockito, PowerMockito and TestNG.</p>
  
  <p>Here is my test code (one of variants):</p>
  
  <pre><code>@Test
  public void should_invoke_parent_logic_methods_of_A_class() throws Exception {
  
      /* Given */
      A aSpy = PowerMockito.spy(new A());
  
      PowerMockito.doReturn(250).when(aSpy, "generifiedMethod", "abc", 100);
      PowerMockito.doNothing().when(aSpy, "method", 250);
      PowerMockito.suppress(method(A.class, "mainMethod", Integer.class));
  
      /* When */
      aSpy.mainMethod(100500);
  
      /* Then */
      /**
       * Here I need to verify invocation of all methods of class A (generifiedMethod(), method(),
       * and mainMethod()). But I don't need them to be invoked because their logic is unwanted
       * to be tested in case of tests for class B.
       */
  }
  </code></pre>
  
  <p>I would be appreciate for any suggestions how to test class B. Thanks.</p>
  
  <p><strong><em>Update</em></strong></p>
  
  <p>If I add into <em>Then</em> section this code</p>
  
  <pre><code>Mockito.verify(aSpy, times(3)).mainMethod(100500);
  Mockito.verify(aSpy, times(1)).generifiedMethod("abc", 100);
  Mockito.verify(aSpy, times(1)).method(250);
  </code></pre>
  
  <p>It gives me the following error message:</p>
  
  <pre><code>Wanted but not invoked:
  a.generifiedMethod("abc", 100);
  </code></pre>