0
您好我有下面的測試,我不能讓它工作,它給NullPointerException
:的Mockito的NullPointerException
方法測試:這種方法的
private ResponseEntity getDefaultCart(HttpEntity<String> request, String zoomQuery) {
LOG.info("Get user's default cart with zoom query" + zoomQuery);
String defaultCartUrl = cortexApiUrl + Constants.CARTS + scope + Constants.DEFAULT + Constants.ZOOM + zoomQuery;
return baseRepository.getCall(defaultCartUrl, request);
}
的Junit:
@Test
public void testUpdateCart() {
MockitoAnnotations.initMocks(this);
cortexRepository= new CortexRepositoryImpl("https://abc.juy", "ocean", baseRepositoryImpl);
Mockito.when(baseRepositoryImpl.createRequestHeaders("guestId")).thenReturn(httpHeaders);
JSONObject orderDetails = createCortexCreateOrderObject("cortexCreateOrderResponse.json");
ResponseEntity<JSONObject> entity=new ResponseEntity<JSONObject>(orderDetails,HttpStatus.ACCEPTED);
HttpEntity<String> request = new HttpEntity<String>(httpHeaders);
Mockito.when(baseRepositoryImpl.getCall("http://www.abc.hyh", request)).thenReturn(entity);
cortexRepository.updateCart(updateCartRequest);
}
方法getDefaultCart
正在調用updateCart
方法。對象orderDetails
正在填充正確。
NUllPointer在線提供:baseRepository.getCall(defaultCartUrl, request)
。
任何建議?