测试类需加注解
模拟静态方法:
PowerMockito.mockStatic(JsonUtil.class);
PowerMockito.when(JsonUtil.parseJson(null)).thenReturn(dicWord);
被测方法中new的对象可以这样模拟(被模拟类需加到@PrepareForTest注解后面):
PowerMockito.whenNew(HadoopHelper.class).withNoArguments().thenReturn(helper); PowerMockito.when(helper.getFileSystem()).thenReturn(null);