How to unit test Java code that is expected to run in the Security Manager applet

I have some Java library code that sometimes runs as an unsigned applet. Because of this, it is not always allowed to perform certain operations (for example, checking system properties).

I would like to run some unit tests using a security manager like Applet, so that I can make sure that the code either does not perform any limited operations or correctly processes any security exceptions.

What is the best way to run these unit tests with a realistic Security-Manager configuration? The preferred solution would be something that can integrate with JUnit.

+3
source share
1 answer

Not a solution as such, but you cannot implement your own SecurityManager subclass, possibly delegating all calls to a "pseudo-security manager", which in turn will mock EasyMock / like? Then you can install this SecurityManager with System.setSecurityManager().

If you know what your applet should do, you can skip the test depending on your requirements.

I may have missed what you want to achieve, but this seems like one possible approach.

+2
source

Source: https://habr.com/ru/post/1730033/


All Articles