Access to private static members of PowerMock

How can I access the next private static foo field from PowerMock. I just want to check that Foo, for example, is not null, and I cannot refactor the code by adding getters.

public class Bar{

   private static Foo foo = new Foo();


}

I try to use this, but it does not work:

Foo foo = Whitebox.getInternalState(bar, "foo");
+4
source share
2 answers

You can use Spring ReflectionTestUtils.getField () for this:

Foo foo = ReflectionTestUtils.getField(Bar.class, "foo");
+1
source

, , : . , , - (: ) , ; , , .

- , - , null . : , , .

, : , Powermock - "" - , , .

: - - ?!
0

Source: https://habr.com/ru/post/1654922/


All Articles