java - How do I set a primitive private static final field in a class with private constructor using PowerMockito? -
i'm trying set private static final field in class private constructor junit test. when boil code down basics, following: public class foo { private static final boolean flag = false; private foo() { /* don't call me */ } public static boolean get() { return flag; } } my tests looks this: @runwith(powermockrunner.class) @prepareeverythingfortest // whitebox fails without line public class footest { @test public void testget() { whitebox.setinternalstate(foo.class, "flag", true); asserttrue(foo.get()); } } and here excerpt pom file: <junit.version>4.11</junit.version> <powermock.version>1.5.4</powermock.version> <mockito.version>1.9.5</mockito.version> when put breakpoint on return flag; , can see flag set true in intellij's debugger. yet test fails assertionerror . any ideas make work? update: using reflection doesn't seem work, either: @test public void te...