TestCases passing locally but getting Nullpointer exception in assessment

My local test cases passing, but during assessment it says null pointer exception. And the lines mentioned in the log consists some comments only.

Please help me out with this.

hello @sbanerjee_1998
looks like you are getting null pointer in the assert statements,
which means that your variables restaurant1…restaurant5 is not getting initialised
also you have 3 methods in the mockitoteststub.java for which I am not sure why you have put in there
1.void setup() {
MockitoAnnotations.initMocks(this);
}
2.loadRestaurantsDuringNormalHours()
3.loadRestaurantsDuringPeakHours()
and also,
you are calling initializeRestaurantObjects() from method itself, is there any way we can use @BeforeEach to reduce this work?

hey @Anmol-Crio_TA,
loadRestaurantsDuringNormalHours() and loadRestaurantsDuringPeakHours() are unused methods which I forgot to erase, I have removed void setup() too. But if restaurant1-restaurant5 is not getting initialised properly, then how is it passing the local test cases? Please explain this and let me know if I am initialising those variables incorrectly.

hello @sbanerjee_1998
your local tests are passing because you are calling initializeRestaurantObjects() method from both the method(3km and 5km),
but the remote tests don’t want to you to call initializeRestaurantObjects()
from methods explicitly.
Is there any way you can use @BeforeEach to satisfy this expectation

In my latest solution I used @BeforeEach in initializeRestaurantObjects() itself. But its still not passing.

@sbanerjee_1998
also in the method mentioned you don’t need
mockitoAnnotations.initMocks() it’s been already done by us
and one more thing
you are using this.restautant1=restaurant[0]
“this” means you are initiating variables for the caller method but we need to initialise them globally so that every method can use it, please remove this from the lines.

hey, These changes didn’t solve my issue.

hey @sbanerjee_1998
I am in your codebase, why do you have merge conflict, you haven’t resolved them yet?

I don’t know what’s the problem but even after pushing solved code, the conflicts are coming back. I am solving conflicts after every push operation.

@sbanerjee_1998
I think there is some system issue, let me push your query to our technical team.

1 Like

hello @sbanerjee_1998
There is no system issue from our side,
please comment out the constructor in RestaurantServiceImpl class which is having mock as argument, because in the mockitoteststub you are using @InjectMocks and @mock with restaurantServiceImpl only which is causing the mocks to misbehave, please try it out and update the thread accordingly. :slight_smile:

Yes, it worked and all test cases are passing now.

One more thing is, merge conflicts are still coming back. Am I doing something wrong?

@sbanerjee_1998
I am not sure about that, please proceed further our technial team is working on this

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.