TestLogin NullPointerException

Hi,
I’ve hit a brick wall with testLogin.

I used to have duplicate key error, but after reading this thread:

I tinkered with my code, but it’s even worse.

java.lang.NullPointerException
at mflix.api.daos.UserTest.testLogin(UserTest.java:85)

Class UserDAO has a field
private final MongoCollection<Session> sessionsCollection;
and method createUserSession keeps throwing NullPointerException

public boolean createUserSession(String userId, String jwt) {
Session session = getUserSession(userId);
if (session == null) {
session = new Session();
session.setUserId(userId);
session.setJwt(jwt);
sessionsCollection.insertOne(session);
return true;
}
return false;
}

Thank you for help

Problem was resolved. Generally the problem In my implementation was wrong mapping in method getUserSession() which can result in methods testLogin() and testRegisterUser() passing, with testDeleteUser() and testLogout() failing. Swapping fields could make it pass all methods but testLogin().

2 Likes

Thank you. After so long debuging I found it