0
@RunWith(PowerMockRunner.class)
@PrepareForTest(StaticMethodsHolder.class)

public class MockNTestStaticMethodsHolder {

  @Rule public PowerMockRule rule = new PowerMockRule();

  @Test public void staticSvcClientMethod () {

    // blah blah blah
    mockstatic (StaticMethodsHolder.class);

    expect (StaticMethodsHolder.TomBradyIsStillTheBest()).andReturn(UNQUESTIONABLY);
    expect (StaticMethodsHolder.NEPatriotsStillTheBest()).andReturn(MAYBE);
    expect (StaticMethodsHolder.NEPatriotsLiiWereIdiots()).andReturn(TOTALLY);
    expect (StaticMethodsHolder.NEPatriotsWinsLiii()).andReturn(RU_KIDDING_ME);

  }

}

Maven dependencies/properties in the following order:

  1. powermock-version 1.6.6
  2. easymock-version 3.4
  3. easymock
  4. powermock-module-junit4
  5. powermock-api-easymock
  6. powermock-module-junit4-rule-agent (removing this causes constructor issues)
  7. powermock-module-junit4-rule (removing this dependency has no effect)
  8. powermock-classloading-xstream

Runtime error:

java.lang.IllegalStateException PowerMockRule can only be used
with the system classloader but was loaded by
org.powermock.core.classloader.MockClassLoader.

PowerMock is biting is own tail. It wants to use its own classloader, but the JVM says PowerMockRule must be loaded by system's.

What can I do to resolve this?

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
  • I am using JDK8. – Blessed Geek Feb 22 '18 at 20:16
  • you shouldn't have any issue with the question you just deleted (https://stackoverflow.com/questions/49056680/how-to-reference-a-function-directly-in-the-functionalinterface-argument-of-a-me). Have you found the solution or was it a simple typo? – Andrew Tobilko Mar 01 '18 at 19:07

1 Answers1

3

You are already using the PowermockRunner, you do not need to use the rule.

https://github.com/powermock/powermock/wiki/powermockrule

if you were using a different runner while requiring Powermock functionality that is the use case for the Rule.

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54