title: NoSuchMethodError in powermock spring boot?
body: <p>Trying to Mock private method "mapCustomerToRule" in the same class with PowerMockito Spy but not able to get it. While it gives NoSuchMethodError.</p>
  
  <p>but it still makes the private method call which in turn makes another thirdPartCall. I'm getting into a problem when thirdPartyCall throws the exception. As far as I understand, if I'm mocking the "mapCustomerToRule", it shouldn't get into method implementation detail and return the mock response.</p>
  
  <pre><code>public Map&lt;String, List&lt;Rule&gt;&gt; fetchCutomerToRules() {
          List&lt;ClaimRuleEntity&gt; listOfDHLClaimsRule = dhlClaimRuleRepository.findAllByOrderByRulePriority();
  
          if (Objects.isNull(listOfDHLClaimsRule) || listOfDHLClaimsRule.isEmpty()) {
              return null;
          }
          log.info("claim rules fetched from database");
  
          List&lt;ClaimRuleCustomerEntity&gt; listOfDHLClaimRuleCustomerEntity = dhlClaimRuleCustomerRepository.findAllByEnabledFlagTrue();
  
      if (Objects.isNull(listOfDHLClaimRuleCustomerEntity) || listOfDHLClaimRuleCustomerEntity.isEmpty()) {
          return null;
      }
      log.info("claim customers fetched from database");
  
      return mapCustomerToRule(listOfDHLClaimsRule, listOfDHLClaimRuleCustomerEntity);
  }
  
  private Map&lt;String, List&lt;Rule&gt;&gt; mapCustomerToRule(List&lt;ClaimRuleEntity&gt; listOfDHLClaimsRule,
          List&lt;ClaimRuleCustomerEntity&gt; listOfDHLClaimRuleCustomerEntity) {
      log.info("mapping started for claim rules to customer");
      Map&lt;String, List&lt;Rule&gt;&gt; cutomerToRules = new HashMap&lt;&gt;();
  
      listOfDHLClaimRuleCustomerEntity.forEach(dhlClaimRuleCustomerEntity -&gt; {
  
          String customer = dhlClaimRuleCustomerEntity.getCustomer();
          List&lt;Rule&gt; rules = cutomerToRules.get(customer);
  
          if (Objects.isNull(rules)) {
              rules = new ArrayList&lt;&gt;();
              cutomerToRules.put(customer, rules);
          }
  
          for (ClaimRuleEntity dhlClaimRule : listOfDHLClaimsRule) {
              if (dhlClaimRule.getRuleId() == dhlClaimRuleCustomerEntity.getRuleId()) {
                  Rule rule = new Rule();
                  rule.setRuleId(dhlClaimRule.getRuleId());
                  rule.setRuleValue(dhlClaimRuleCustomerEntity.getRuleValue());
                  rule.setRulePriority(dhlClaimRule.getRulePriority());
                  rule.setEnabled(dhlClaimRuleCustomerEntity.getEnabledFlag());
                  rule.setRuleDescription(dhlClaimRule.getRuleDescription());
                  rules.add(rule);
                  break;
              }
          }
      });
      log.info("mapping completed for claim rules to customer");
      return cutomerToRules;
  
  }
  </code></pre>
  
  <p>Here is the juint I wrote for classs</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PowerMockRunnerDelegate(SpringRunner.class)
  @PrepareForTest(FetchUpdateClaimService.class)
  @ContextConfiguration(classes = ProcessClaimTestConfiguration.class)
  public class FetchUpdateClaimServiceTest {
  
      @Autowired
      FetchUpdateClaimService fetchUpdateClaimService;
  
      @Autowired
      ClaimRuleRepository dhlClaimRuleRepository;
  
      @Autowired
      ClaimRuleCustomerRepository dhlClaimRuleCustomerRepository;
  
      @Autowired
      ClaimRepository dhlClaimRepository;
  
      @Before
      public void init() {
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void fetchCutomerToRules_should_pass_Test() throws Exception {
          FetchUpdateClaimService fetchUpdateClaimService = PowerMockito.spy(this.fetchUpdateClaimService);
          List&lt;ClaimRuleEntity&gt; listOfDHLClaimsRule = new ArrayList&lt;&gt;();
          ClaimRuleEntity claimRuleEntity = new ClaimRuleEntity();
          listOfDHLClaimsRule.add(claimRuleEntity);
  
          List&lt;ClaimRuleCustomerEntity&gt; listOfDHLClaimRuleCustomerEntity = new ArrayList&lt;&gt;();
          ClaimRuleCustomerEntity claimRuleCustomerEntity = new ClaimRuleCustomerEntity();
          listOfDHLClaimRuleCustomerEntity.add(claimRuleCustomerEntity);
  
          Map&lt;String, List&lt;Rule&gt;&gt; map = new HashMap&lt;&gt;();
          Mockito.when(dhlClaimRuleRepository.findAllByOrderByRulePriority()).thenReturn(listOfDHLClaimsRule);
          Mockito.when(dhlClaimRuleCustomerRepository.findAllByEnabledFlagTrue()).thenReturn(listOfDHLClaimRuleCustomerEntity);
  
          PowerMockito.doReturn(map).when(fetchUpdateClaimService,"mapCustomerToRule",Mockito.eq(List.class),Mockito.eq(List.class));
  
          this.fetchUpdateClaimService.fetchCutomerToRules();
  
      }
  
  }
  </code></pre>
  
  <p>Error Stack:-</p>
  
  <pre><code>java.lang.NoSuchMethodError: org.mockito.internal.handler.MockHandlerFactory.createMockHandler(Lorg/mockito/mock/MockCreationSettings;)Lorg/mockito/internal/InternalMockHandler;
      at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMethodInvocationControl(DefaultMockCreator.java:114)
      at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:69)
      at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:46)
      at org.powermock.api.mockito.PowerMockito.spy(PowerMockito.java:207)
      at com.morrison.process.claim.service.FetchUpdateClaimServiceTest.fetchCutomerToRules_should_pass_Test(FetchUpdateClaimServiceTest.java:54)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
      at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:149)
      at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:141)
      at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.java:132)
      at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.java:141)
      at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
      at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
      at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
  </code></pre>
  
  <p>My Pom.xml</p>
  
  <pre><code>&lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.retry&lt;/groupId&gt;
              &lt;artifactId&gt;spring-retry&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-aws&lt;/artifactId&gt;
              &lt;version&gt;${apache.camel.aws.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.vladmihalcea&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-types-52&lt;/artifactId&gt;
              &lt;version&gt;2.2.0&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.powermock&lt;/groupId&gt;
              &lt;artifactId&gt;powermock-module-junit4&lt;/artifactId&gt;
              &lt;version&gt;1.7.4&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.powermock&lt;/groupId&gt;
              &lt;artifactId&gt;powermock-api-mockito2&lt;/artifactId&gt;
              &lt;version&gt;1.7.4&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
  
  
      &lt;/dependencies&gt;
  </code></pre>