Last active
February 21, 2022 10:40
-
-
Save BjoernKW/59a2c8dd4edbe8f79510c83fb5211449 to your computer and use it in GitHub Desktop.
Minimal JUnit test setup with security context and a mocked user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void testMethod() throws Exception { | |
SecurityContextHolder.setContext( | |
SecurityContextHolder.createEmptyContext() | |
); | |
SecurityContextHolder.getContext().setAuthentication( | |
new TestingAuthenticationToken("TEST_USER", null) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also see https://gist.github.com/BjoernKW/0b9cb56dd3884a8bbbebedb6cc77718f and this code snippet using that factory: