@@ -0,0 +1,2292 @@
+package com.coding4people.mosquitoreport.api.factories;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport javax.ws.rs.ForbiddenException;%0Aimport javax.ws.rs.container.ContainerRequestContext;%0A%0Aimport org.junit.Test;%0Aimport org.mockito.Mock;%0A%0Aimport com.coding4people.mosquitoreport.api.WithService;%0Aimport com.coding4people.mosquitoreport.api.models.User;%0Aimport com.coding4people.mosquitoreport.api.repositories.UserRepository;%0A%0Apublic class CurrentUserFactoryTest extends WithService %7B%0A    @Mock%0A    UserRepository userRepository;%0A%0A    @Mock%0A    ContainerRequestContext requestContext;%0A%0A    @Test(expected = ForbiddenException.class)%0A    public void testThrowsForbiddenExceptionWhenThereIsNoAuthorizationHeader() %7B%0A        when(requestContext.getHeaderString(%22Authorization%22)).thenReturn(null);%0A%0A        new CurrentUserFactory(userRepository, requestContext);%0A    %7D%0A%0A    @Test(expected = ForbiddenException.class)%0A    public void testThrowsForbiddenExceptionWhenTokenIsInvalid() %7B%0A        when(requestContext.getHeaderString(%22Authorization%22)).thenReturn(%22Token invalidtoken%22);%0A%0A        new CurrentUserFactory(userRepository, requestContext);%0A    %7D%0A%0A    @Test(expected = ForbiddenException.class)%0A    public void testThrowsForbiddenExceptionWhenUserNotFound() %7B%0A        when(requestContext.getHeaderString(%22Authorization%22))%0A                .thenReturn(%22Token MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw%22);%0A        when(userRepository.load(%2200000000-0000-0000-0000-000000000000%22)).thenReturn(null);%0A%0A        new CurrentUserFactory(userRepository, requestContext);%0A%0A        verify(userRepository).load(%2200000000-0000-0000-0000-000000000000%22);%0A    %7D%0A%0A    @Test%0A    public void testProvide() %7B%0A        User user = new User();%0A%0A        when(requestContext.getHeaderString(%22Authorization%22))%0A                .thenReturn(%22Token MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw%22);%0A        when(userRepository.load(%2200000000-0000-0000-0000-000000000000%22)).thenReturn(user);%0A%0A        CurrentUserFactory factory = new CurrentUserFactory(userRepository, requestContext);%0A%0A        verify(userRepository).load(%2200000000-0000-0000-0000-000000000000%22);%0A        %0A        assertEquals(user, factory.provide());%0A    %7D%0A%7D%0A

Test CurrentUserFactory