Are you using a mock framework like Mockito or EasyMock? Here is an example
that uses EasyMock (and still sets up the thread context):
https://github.com/apache/shiro/blob/master/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java


On Sat, Dec 5, 2020 at 8:12 AM Alex Orlov <[email protected]> wrote:

> Hello all,
>
> I am trying to build mock subject for my tests. In my system I use the
> following code to check authorization:
>         var permission = new ResourcePermission(this.getResourceId(),
> action);
>         if (!subject.isPermitted(permission)) {
>             throw new AuthorizationException();
>         }
>
> Now, I am trying to build a mock subject for my test:
>
>         Subject subjectUnderTest = new Subject
>                 .Builder(securityManager)
>                 .authenticated(true)
>                 .???
>                 .buildSubject();
>
> Could anyone say, how to build a mock subject having certain permissions?
> Or do I miss something?
>
>
>
>
> --
> Best regards, Alex Orlov
>

Reply via email to