SecurityContextHolder
keeps a reference to a "strategy" in a static variable which means that this detail leaks from test to test.
You have several options:
In your test, set the correct strategy using one of the setters of
SecurityContextHolder
Create a mock implementation for
getCurrentUserStudentId
which returns a fixed result for the test.Put the code to get the current user id into a bean and inject that instead of calling
SecurityContextHolder
. Implement two versions of this bean: One which callsSecurityContextHolder
and another which returns a string.