我正在尝试测试以下代码:
GSARepository productCatalog = (GSARepository) Nucleus.getGlobalNucleus().resolveName("/atg/commerce/catalog/ProductCatalog");
for (RepositoryItem orderItem : orderItems) {
String product = (String) orderItem.getPropertyValue(PropertyNameConstants.PRODUCTID);
if (!ProductUtils.isSpecial(product, productCatalog)) {
isSpecial = false;
break;
}
}
显然 Nucleus.getGlobalNucleus() 是静态的。
根据文档,我应该能够使用:
PowerMockito.mockStatic(Nucleus.class);
PowerMockito.when(Nucleus.getGlobalNucleus()).thenReturn(globalNucleusMock);
PowerMockito.when(globalNucleusMock.resolveName("/atg/commerce/catalog/ProductCatalog");
不管怎样,当我调用时,我仍然得到一个空指针:
Nucleus.getGlobalNucleus().resolveName("/atg/commerce/catalog/ProductCatalog")