/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.trellisldp.http;

import static java.util.Collections.emptyList;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.trellisldp.http.domain.HttpConstants.SESSION_PROPERTY;

import java.security.Principal;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.SecurityContext;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import org.trellisldp.api.AgentService;
import org.trellisldp.api.Session;
import org.trellisldp.vocabulary.Trellis;

/**
 * @author acoburn
 */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@RunWith(JUnitPlatform.class)
public class AgentAuthorizationFilterTest {

    @Mock
    private AgentService mockAgentService;

    @Mock
    private ContainerRequestContext mockContext;

    @Mock
    private SecurityContext mockSecurityContext;

    @Mock
    private Principal mockPrincipal;

    @BeforeEach
    public void setUp() {
        initMocks(this);
        when(mockAgentService.asAgent(any())).thenReturn(Trellis.AnonymousUser);
        when(mockContext.getSecurityContext()).thenReturn(mockSecurityContext);
        when(mockSecurityContext.getUserPrincipal()).thenReturn(mockPrincipal);
    }

    @Test
    public void testFilterMissingAgent() throws Exception {
        when(mockPrincipal.getName()).thenReturn("");
        final AgentAuthorizationFilter filter = new AgentAuthorizationFilter(mockAgentService, emptyList());

        filter.filter(mockContext);
        verify(mockContext).setProperty(eq(SESSION_PROPERTY), any(Session.class));
    }
}

@@ -628,24 +628,85 @@
 .emptyList;%0A
+import static org.junit.jupiter.api.Assertions.assertEquals;%0A
 import stati
@@ -741,16 +741,16 @@
 rs.any;%0A
-
 import s
@@ -1329,16 +1329,78 @@
 unWith;%0A
+import org.mockito.ArgumentCaptor;%0Aimport org.mockito.Captor;%0A
 import o
@@ -1907,16 +1907,82 @@
 cipal;%0A%0A
+    @Captor%0A    private ArgumentCaptor%3CSession%3E sessionArgument;%0A%0A
     @Bef
@@ -2624,25 +2624,116 @@
 Y), 
-any(Session.class
+sessionArgument.capture());%0A        assertEquals(Trellis.AnonymousUser, sessionArgument.getValue().getAgent(
 ));%0A

Add argument captor to agent test