I'm writing tests for my pet-project. Right now, I'm stuck with unit testing. I have a big method called "check-ownership", that returns an enum value.
During a run, this method changes numerous amount of objects.
Part of my method:
if(aruCalls.size() == 0) {
aruCallDtoRequest.setDopFlag(0);
}
Take a look at aruCallDtoRequest.setDopFlag(0); line
Here is my test:
@ExtendWith(MockitoExtension.class)
class ReRegistrationServiceImplTest {
@InjectMocks
private ReRegistrationServiceImpl reRegistrationServiceImpl;
@Mock
private IntegrationClient integrationClient;
@Mock
private AruCallsService aruCallsService;
@Mock
private AruRequestService aruRequestService;
@Mock
private DealerService dealerService;
private Dealer dealer;
private Location location;
private LocalDateTime currentTime;
private CheckRegistrationDtoRequest checkRegistrationDtoRequest;
private AruCallDtoRequest aruCallDtoRequest;
private AruRequest aruRequest;
private AruRequestDtoRequest aruRequestDtoRequest;
private ResponseEntity<List<UsageDetailDtoResponse>> outgoingCalls;
@BeforeEach
public void init() throws H1NotAllowed, H1NotFound {
aruCallDtoRequest = AruCallDtoRequest.builder()
.customerMsisdn(TEST_NUMBER)
.aruRequestsId(null).build();
}
@Test
@DisplayName("Test for checking of Aru Request Creating at the initialization of the checkOwnership method")
public void test_aruCallsSizeIsEqualToZeroAndAruRequestHasBeenCreated() throws H1NotAllowed, H1NotFound {
verify(dealerService).findMe();
verify(integrationClient).getLocation(TEST_NUMBER);
verify(aruCallsService).findAllByOnRegisteredBetween(currentTime.minusHours(24),TEST_NUMBER);
verify(aruRequestService).create(new AruRequestDtoRequest());
assertEquals(result,CheckOwnershipDtoResponse.MORE_NUMBERS_NEEDED);
}
Every time I run it, I receive a NPE at the line with the "aruCallDtoRequest.setDopFlag(0)". Any ideas how to get rid of this exception?