You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I checked to make sure that this issue has not already been filed
Expected Behavior
After unmocking, I would expect that the SecurityContextHolder is back in its normal operation mode.
Current Behavior
When executing anything on SecurityContextHolder like getContext() after unmocking, a NullPointerException is thrown, as the internal strategy field is not initialized.
Failure Information (for bugs)
Steps to Reproduce
You need the dependency for the spring class SecurityContextHolder
Write a Junit5 test like below
Execute it and you will get the NPE
Context
MockK version: 1.12.3
OS: Windows 10
Kotlin version: 1.6.10
JDK version: 11-temurin
JUnit version: 5.8.2
Type of test: unit test
Minimal reproducible code
importio.mockk.clearAllMocksimportio.mockk.everyimportio.mockk.justimportio.mockk.mockkStaticimportio.mockk.runsimportorg.junit.jupiter.api.Testimportorg.springframework.security.core.context.SecurityContextHolderclassMyTest {
@Test
funtest() {
// Mock
mockkStatic(SecurityContextHolder::class) // when replaced with mockkStatic(SecurityContextHolder::class.qualifiedName!!), everything works
every { SecurityContextHolder.clearContext() } just runs // without this line, everything works// Unmock
clearAllMocks()
// Try to get SecurityContext -> throws NPE, but should notSecurityContextHolder.getContext()
}
}
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.
Prerequisites
Expected Behavior
After unmocking, I would expect that the
SecurityContextHolder
is back in its normal operation mode.Current Behavior
When executing anything on
SecurityContextHolder
likegetContext()
after unmocking, a NullPointerException is thrown, as the internalstrategy
field is not initialized.Failure Information (for bugs)
Steps to Reproduce
SecurityContextHolder
Context
Minimal reproducible code
The text was updated successfully, but these errors were encountered: