Powermock - Mock final Classes - BootstrapSecurityManager

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Powermock - Mock final Classes - BootstrapSecurityManager

dkuffner
This post has NOT been accepted by the mailing list yet.

Unit Test with default java security manager

Hi All,
I use powermock. I use also advanced feature to mock classes which are declared as 'final'. In order to make that work I have to set the security manager of the test execution to the default java security manager

test {
            useTestNG()
            doFirst {
                def agent = project.configurations.agent.asPath
                def policy = rootProject.file('osgi/security.policy')
                // Gradle will execute the tests with a own security manager.
                // This security manager will make PowerMock tests fail
                // Note: -Djava.security.manager <- doesn't work, manager must be specified explicitly.
                jvmArgs.add "-Djava.security.manager=java.lang.SecurityManager"
                jvmArgs.add "-Djava.security.policy=${policy}"
                jvmArgs.add "-javaagent:${agent}"
                jvmArgs.add "-XX:MaxPermSize=512m"
                ignoreFailures true
            }
In general that works fine but from time to time the tests fail. It seems like that sometimes a test case will be executed with the gradle security manager (BootstrapSecurityManager) and sometimes with the the default java security manager.

Any idea why it behaves inconsistent from build to build?

reagrds,
Daniel