@@ -0,0 +1,2823 @@
+package ru.otus.kirillov.model.commands.login;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport ru.otus.kirillov.model.commands.Result;%0Aimport ru.otus.kirillov.model.commands.common.ErroneousResult;%0Aimport ru.otus.kirillov.model.service.auth.AuthService;%0Aimport ru.otus.kirillov.model.service.auth.StubAuthServiceImpl;%0Aimport ru.otus.kirillov.utils.AESSecurity;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.Mockito.*;%0Aimport static ru.otus.kirillov.model.service.auth.StubAuthServiceImpl.*;%0A%0Apublic class LoginCommandTest %7B%0A%0A    private LoginCommand command;%0A    private AuthService authServiceMock;%0A    private AESSecurity aesSecurityMock;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        authServiceMock = mock(AuthService.class);%0A        aesSecurityMock = mock(AESSecurity.class);%0A        command = new LoginCommand(authServiceMock, aesSecurityMock);%0A%0A        when(aesSecurityMock.encrypt(DUMMY_USERNAME))%0A                .thenReturn(DUMMY_ENCRYPTED_USERNAME);%0A        when(aesSecurityMock.encrypt(DUMMY_PASSWORD))%0A                .thenReturn(DUMMY_ENCRYPTED_PASSWORD);%0A    %7D%0A%0A    public static final String DUMMY_USERNAME = %22###DUMMY_USERNAME###%22;%0A    public static final String DUMMY_ENCRYPTED_USERNAME = %22###DUMMY_ENCRYPTED_USERNAME###%22;%0A%0A    public static final String DUMMY_PASSWORD = %22###DUMMY_PASSWORD###%22;%0A    public static final String DUMMY_ENCRYPTED_PASSWORD = %22###DUMMY_ENCRYPTED_PASSWORD###%22;%0A%0A    public static final String DUMMY_SESSION_ID = %22###DUMMY_SESSION_ID###%22;%0A%0A    @Test%0A    public void testSuccess() %7B%0A        when(authServiceMock.login(DUMMY_ENCRYPTED_USERNAME, DUMMY_ENCRYPTED_PASSWORD))%0A                .thenReturn(DUMMY_SESSION_ID);%0A%0A        Result result = command.execute(LoginRequest.of(DUMMY_USERNAME, DUMMY_PASSWORD));%0A        LoginResult loginResult = (LoginResult) result;%0A%0A        assertEquals(DUMMY_ENCRYPTED_USERNAME, loginResult.getUserName());%0A        assertEquals(DUMMY_SESSION_ID, loginResult.getSessionId());%0A        verifyMockCallCount();%0A    %7D%0A%0A    @Test%0A    public void testWrongLoginOrPassword() %7B%0A        when(authServiceMock.login(DUMMY_ENCRYPTED_USERNAME, DUMMY_ENCRYPTED_PASSWORD))%0A                .thenThrow(new NotAuthorizedException(DUMMY_USERNAME, DUMMY_PASSWORD));%0A%0A        ErroneousResult result =%0A                (ErroneousResult) command.execute(LoginRequest.of(DUMMY_USERNAME, DUMMY_PASSWORD));%0A%0A        assertNotNull(result.getCause());%0A%0A        verifyMockCallCount();%0A    %7D%0A%0A    private void verifyMockCallCount() %7B%0A        verify(aesSecurityMock, times(2))%0A                .encrypt(anyString());%0A        verify(authServiceMock, only())%0A                .login(DUMMY_ENCRYPTED_USERNAME, DUMMY_ENCRYPTED_PASSWORD);%0A    %7D%0A%7D

add test for login