--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Ok, I think I’ve gotten past this particular problem, but it’s still not quite right.
This is what I’m left with at the beginning of the class:
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bar.class, GenericContext.class, ResourceBundle.class})
@SuppressStaticInitializationFor({"bar.GenericContext", "bar.Bar"})
public class RTIUtilsTest {
private RTIUtils rtiUtils = new RTIUtils();
@Mock
private Bar bar;
@Mock
private ItemManager itemManager;
@Mock
private ResourceBundle resourceBundle;
@Before
public void setup() {
PowerMockito.mockStatic(Bar.class);
PowerMockito.mockStatic(GenericContext.class);
PowerMockito.mockStatic(ResourceBundle.class);
suppress(constructor(GenericContext.class));
suppress(constructor(Bar.class));
PowerMockito.when(Bar.getGlobalBar()).thenReturn(bar);
when(bar.resolveName(anyString())).thenReturn(itemManager);
PowerMockito.when(ResourceBundle.getBundle(anyString())).thenReturn(resourceBundle);
}
Now I’m getting a NPE inside the “Bar.getGlobalBar()” method, because the code references an instance variable I haven’t wired in. As far as I can tell, it shouldn’t be getting into the method, because I’ve mocked the static methods of “Bar”, and I have a when clause for that method. Why is it getting into the method?
I think I figured this out. I neglected to suppress static initialization for my class under test, which also defines statics and initializes them with calls to static methods.