Posts

Showing posts from May, 2023

Eclipse getting stuck at reporting encoding changes

 Eclipse was getting stuck at reporting encoding changes solution for me was to disconnect from office VPN and it worked.

Null pointer exception when stubbing a method

/#-----------Null pointer exception when stubbing a method. check the syntax of your stub //# for me it was  doReturn(responseEntity).when(rhpp.invokeDownStreamService(apiRequestService, traceId)); // this variable needs some other values to be set like url and good status ....use reflection api to set this field variables. Follow this link to understand partial Mocking. https://stackoverflow.com/questions/14970516/use-mockito-to-mock-some-methods-but-not-others Also understand difference between doReturn.when vs When.thenReturn. To directly answer your question, yes, you can mock some methods without mocking others. This is called a partial mock. See the Mockito documentation on partial mocks for more information. For your example, you can do something like the following, in your test: Stock stock = mock(Stock.class); when(stock.getPrice()).thenReturn(100.00);    // Mock implementation when(stock.getQuantity()).thenReturn(200);    // Mock implementation when(st...