commit 527af170433f519500614a92955762a4bbdf80b6
Author: Hrabikv <hrabikv@students.zcu.cz>
Date:   Thu Apr 13 23:03:25 2023 +0200

    #10368 testy pro userservice

diff --git a/pom.xml b/pom.xml
index 4ebd477..9de5989 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,8 +140,19 @@
 			<artifactId>spring-security-test</artifactId>
 			<scope>test</scope>
 		</dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-inline</artifactId>
+			<version>4.3.1</version>
+			<scope>test</scope>
+		</dependency>
 
-	</dependencies>
+    </dependencies>
 
 	<build>
 		<plugins>
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImpl.java
index 3d54be8..f18c1df 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImpl.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImpl.java
@@ -23,7 +23,7 @@ import java.util.HashMap;
  * Service which communicate with OAuth application
  */
 @Service
-public class OAuthServiceImpl implements OAuthService, UserDetailsService, AuthenticationEntryPoint {
+public class OAuthServiceImpl implements OAuthService, UserDetailsService {
 
     /**
      * URL path to authenticate endpoint of OAuth application
@@ -49,27 +49,12 @@ public class OAuthServiceImpl implements OAuthService, UserDetailsService, Authe
     @Autowired
     private UserService userService;
 
-    @Override
-    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
-            throws IOException, ServletException {
-        String authorizationHeader = request.getHeader("Authorization");
-        if (authorizationHeader == null || authorizationHeader.length() < 7) {
-            return;
-        }
-        String token = authorizationHeader.substring(7);
-
-        ResponseEntity<String> responseEntity = authenticate(token);
-         if (token != null && responseEntity.getBody().contains("OK")) {
-            // Token is valid, proceed with the request
-            response.setStatus(501);
-        } else {
-            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-        }
-    }
+
+    private RequestBuilder requestBuilder = new RequestBuilder();
 
     public ResponseEntity<String> authenticate(String token) {
 
-        return RequestBuilder.sendRequestResponse(AUTH_URL_AUTH, token);
+        return requestBuilder.sendRequestResponse(AUTH_URL_AUTH, token);
     }
 
     public ResponseEntity<String> loginUser(User user) {
@@ -83,7 +68,7 @@ public class OAuthServiceImpl implements OAuthService, UserDetailsService, Authe
 
         requestBody.put("name", userName);
 
-        return RequestBuilder.sendRequestResponse(AUTH_URL_LOGIN, requestBody);
+        return requestBuilder.sendRequestResponse(AUTH_URL_LOGIN, requestBody);
     }
 
     public ResponseEntity<String> logoutUser(User user) {
@@ -100,7 +85,7 @@ public class OAuthServiceImpl implements OAuthService, UserDetailsService, Authe
         requestBody.put("name", userName);
         requestBody.put("token", token);
 
-        return RequestBuilder.sendRequestResponse(AUTH_URL_LOGOUT, requestBody);
+        return requestBuilder.sendRequestResponse(AUTH_URL_LOGOUT, requestBody);
     }
 
     @Override
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
index 0447986..486777e 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserService.java
@@ -21,12 +21,6 @@ public interface UserService {
      * @return Integer - status code of the operation, ie 1 - successful, 0 - failed, ....
      */
     public UserModelStatusCodes verifyUser(User user);
-    /**
-     * Method attempts to log out a user
-     * @param user serialized JSON object representing user
-     * @return Integer - status code of the operation, ie 1 - successful, 0 - failed, ....
-     */
-    public UserModelStatusCodes logoutUser(User user);
 
     public User getUserByName(String name);
 
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
index 55f0c4f..7bba75e 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java
@@ -89,7 +89,7 @@ public class UserServiceImpl implements UserService {
      * @param password  password from client
      * @return          hashed password for database
      */
-    private String hashPassword(String password) {
+    public String hashPassword(String password) {
         //standard java security encryption module
         MessageDigest digest = null;
         try {
@@ -142,17 +142,6 @@ public class UserServiceImpl implements UserService {
         return hash.equals(passwordHash);
     }
 
-    /**
-     * Methods invalidates JWT token in OAuth application
-     * @param user serialized JSON object representing user
-     * @return UserModelStatusCodes user logged out status flag
-     */
-    @Override
-    public UserModelStatusCodes logoutUser(User user) {
-        //TODO with OAuth app
-        return UserModelStatusCodes.USER_LOGGED_OUT;
-    }
-
     @Override
     public User getUserByName(String name) {
         return this.userRepository.findByName(name);
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/RequestBuilder.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/RequestBuilder.java
index 842c53a..89f2738 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/RequestBuilder.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/RequestBuilder.java
@@ -1,5 +1,6 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils;
 
+import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.HashMap;
@@ -15,8 +16,10 @@ public class RequestBuilder {
 
     private static Logger logger = Logger.getLogger(RequestBuilder.class.getName());
 
+    public RequestBuilder() {
+    }
 
-    public static ResponseEntity<String> sendRequestResponse(String url, HashMap<String,String> body) {
+    public ResponseEntity<String> sendRequestResponse(String url, HashMap<String, String> body) {
         RestTemplate restTemplate = new RestTemplate();
         String json = JSONBuilder.buildJson(body);
 
@@ -26,7 +29,7 @@ public class RequestBuilder {
         return restTemplate.postForEntity(url, entity, String.class);
     }
 
-    public static ResponseEntity<String> sendRequestResponse(String url, String token) {
+    public ResponseEntity<String> sendRequestResponse(String url, String token) {
         RestTemplate restTemplate = new RestTemplate();
 
         HttpHeaders headers = new HttpHeaders();
diff --git a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
index d40f079..63b00d3 100644
--- a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
+++ b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserControllerTest.java
@@ -137,26 +137,4 @@ public class UserControllerTest {
         assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
     }
 
-    @Test
-    public void logoutUser() throws Exception {
-        Mockito.when(userService.logoutUser(any())).thenReturn(UserModelStatusCodes.USER_LOGGED_OUT);
-        HashMap<String,String> map = new HashMap<>();
-        map.put("name","pepa");
-        map.put("password","ahojSvete");
-        map.put("email","yxz");
-        String json = JSONBuilder.buildJson(map);
-        RequestBuilder requestBuilder = MockMvcRequestBuilders
-                .post("/v2/user/logout")
-                .accept(MediaType.APPLICATION_JSON).content(json)
-                .contentType(MediaType.APPLICATION_JSON);
-
-        MvcResult result = mockMvc.perform(requestBuilder).andReturn();
-
-        MockHttpServletResponse response = result.getResponse();
-
-        assertEquals(HttpStatus.OK.value(), response.getStatus());
-    }
-
-
-
 }
diff --git a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImplTest.java b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImplTest.java
new file mode 100644
index 0000000..fd6ab9b
--- /dev/null
+++ b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/OAuthServiceImplTest.java
@@ -0,0 +1,81 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.UserModelStatusCodes;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.RequestBuilder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class OAuthServiceImplTest {
+
+    @Autowired
+    private OAuthService oAuthService;
+
+    @MockBean
+    private RequestBuilder requestBuilder;
+
+    /**
+     * Mocked User
+     */
+    private final User mockUser = new User("foo", "foo@foo.cz", "foo");
+    
+    @Test
+    public void loginValidUser(){
+        ResponseEntity<String> response = ResponseEntity.ok().body("eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIyMGU4NmJiMC1lMDU4LTQwYTMtYjQyZC02ZTBjOWIyMmQ5MWQiL" +
+                "CJzdWIiOiJmb28iLCJpYXQiOjE2ODE0MTY2ODAsImV4cCI6MTY4MTQxNjk4MH0.YJTwPEI4njQqYRuLGilf_oVl0gGD5BWFmdolk1O" +
+                "vYWIgTcoIAFwh6bwqrW7XM6Hlj-ItYj9EmihYIqN5gfJVtg");
+        HashMap<String, String> hashMap = new HashMap<>();
+        hashMap.put("name", mockUser.getName());
+//        when(requestBuilder.sendRequestResponse(anyString(), anyCollection())).thenReturn(response);
+//        try(MockedStatic<RequestBuilder> requestBuilderMockedStatic = Mockito.mockStatic(RequestBuilder.class)){
+//                requestBuilderMockedStatic.when(() -> RequestBuilder.sendRequestResponse(anyString(), mockHashMap)).thenReturn(response);
+//        }
+
+        ResponseEntity<String> response1 = oAuthService.loginUser(mockUser);
+
+        assertEquals(response, response1);
+
+    }
+
+
+    /*    public ResponseEntity<String> loginUser(User user) {
+        final String userName = user.getName();
+
+        if(userName == null) {
+            return null;
+        }
+        //HttpURLConnection con = RequestBuilder.createConnection(AUTH_URL);
+        HashMap<String, String> requestBody = new HashMap<>();
+
+        requestBody.put("name", userName);
+
+        return RequestBuilder.sendRequestResponse(AUTH_URL_LOGIN, requestBody);
+    }
+     */
+
+
+
+
+
+
+
+
+
+}
diff --git a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
index d5d01e4..47e25ab 100644
--- a/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
+++ b/src/test/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpTest.java
@@ -3,47 +3,30 @@ package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.UserModelStatusCodes;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserRepository;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mockito;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
-import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.security.test.context.support.WithMockUser;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.context.junit4.SpringRunner;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * Tests for userServiceImplementation
  */
-@ExtendWith(SpringExtension.class)
-@WebMvcTest(value = UserServiceImpl.class)
-@WithMockUser
+@RunWith(SpringRunner.class)
+@SpringBootTest
 public class UserServiceImpTest {
 
-    @TestConfiguration
-    static class UserServiceImlpTestConfig{
-
-        @Bean
-        public UserService userService() {
-            return new UserServiceImpl();
-        }
-    }
-
     /**
      * UserService
      */
     @Autowired
     private UserService userService;
 
-
-
     /**
      * Mocked userRepository
      */
@@ -55,8 +38,21 @@ public class UserServiceImpTest {
      */
     private final User mockUser = new User("test", "test@tt.cz", "Ahoj99");
 
+    /* <-------- REGISTRATION TESTING --------> */
+
+    /**
+     * To test happy-day scenario where everything is ok
+     */
+    @Test
+    public void whenUserIsNotRegistered_thenRegisterHim() {
+        when(userRepository.save(any())).thenReturn(mockUser);
+
+        UserModelStatusCodes foundCode = userService.registerUser(mockUser);
+
+        assertEquals(UserModelStatusCodes.USER_CREATED, foundCode);
+    }
+
     /**
-     * Testing registration implementation
      * To test scenario where user want register which name, with more than 255 chars
      */
     @Test
@@ -69,11 +65,10 @@ public class UserServiceImpTest {
                 "dddddddddddhfbsdjfhbsdjhbjckvxjhbvjhfbsjhbdjhsbvhbsckjhvbsdhfbsdjhvbjxhcbvhbjhvbxcv", "tt@aa.ct");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
     /**
-     * Testing registration implementation
      * To test scenario where user want register which email, with more than 255 chars
      */
     @Test
@@ -85,11 +80,43 @@ public class UserServiceImpTest {
                 "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddt@aa.ct");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
+    }
+
+    /**
+     * To test scenario where user want register which email, with email without "@"
+     */
+    @Test
+    public void whenUserEmailIsInvalid_02_thenReturnMSG() {
+        User MUser = new User("Petr", "testaa.ct");
+        UserModelStatusCodes foundCode = userService.registerUser(MUser);
+
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
+    }
+
+    /**
+     * To test scenario where user want register which email, with email without "."
+     */
+    @Test
+    public void whenUserEmailIsInvalid_03_thenReturnMSG() {
+        User MUser = new User("Petr", "test@aact");
+        UserModelStatusCodes foundCode = userService.registerUser(MUser);
+
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
+    }
+
+    /**
+     * To test scenario where user want register which email, with email without "@" and "."
+     */
+    @Test
+    public void whenUserEmailIsInvalid_04_thenReturnMSG() {
+        User MUser = new User("Petr", "testaact");
+        UserModelStatusCodes foundCode = userService.registerUser(MUser);
+
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
     /**
-     * Testing registration implementation
      * To test scenario where user want register which name and email, with more than 255 chars
      */
     @Test
@@ -107,119 +134,161 @@ public class UserServiceImpTest {
                 "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddt@aa.ct");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where username is empty
+     */
     @Test
     public void whenUserNULLName_thenReturnMSG() {
         User MUser = new User(null, "tt@asd.cf", "Ahoj99");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
-
+    /**
+     * scenario where email is empty
+     */
     @Test
     public void whenUserNULLEmail_thenReturnMSG() {
         User MUser = new User("tt", null, "Ahoj99");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where  password is empty
+     */
     @Test
     public void whenUserNULLPassword_thenReturnMSG() {
         User MUser = new User("tt", "tt@asd.cf", null);
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where username and email is empty
+     */
     @Test
     public void whenUserNULLNameEmail_thenReturnMSG() {
         User MUser = new User(null, null, "Ahoj99");
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where username and password is empty
+     */
     @Test
     public void whenUserNULLNamePassword_thenReturnMSG() {
         User MUser = new User(null, "tt@asd.cf", null);
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where email and password is empty
+     */
     @Test
     public void whenUserNULLEmailPassword_thenReturnMSG() {
         User MUser = new User("tt", null, null);
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
+    /**
+     * scenario where username, password, and email is empty
+     */
     @Test
     public void whenUserNULLNameEmailPassword_thenReturnMSG() {
         User MUser = new User(null, null, null);
         UserModelStatusCodes foundCode = userService.registerUser(MUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.INVALID_USER_ARGUMENTS);
+        assertEquals(UserModelStatusCodes.INVALID_USER_ARGUMENTS, foundCode);
     }
 
     /**
-     * Testing registration implementation
-     * To test happy-day scenario where everything is ok
+     * To test scenario where user want to register with name, that is already taken
      */
     @Test
-    public void whenUserIsNotRegistered_thenRegisterHim() {
-        Mockito.when(userRepository.save(any())).thenReturn(mockUser);
+    public void whenUserIsRegistered_thenSendMSG() {
+        when(userRepository.findByName(any())).thenReturn(mockUser);
 
         UserModelStatusCodes foundCode = userService.registerUser(mockUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.USER_CREATED);
+        assertEquals(UserModelStatusCodes.USER_EXISTS, foundCode);
     }
 
+    /* <-------- USER VERIFICATION TESTING --------> */
+
     /**
-     * Testing registration implementation
-     * To test scenario where user want to register which name, that is already taken
+     * for happy-day scenario user is registered
      */
     @Test
-    public void whenUserIsRegistered_thenSendMSG() {
-        Mockito.when(userRepository.findByName(mockUser.getName())).thenReturn(mockUser);
+    public void whenUserIsRegistered_thenVerifyHim() {
+        String name = mockUser.getName();
+        String password = "C63293087805FC0E63564B1F389A85DE00A369B01F3B4B0D0F3A949F565D2765";
+        String email = mockUser.getEmail();
 
-        UserModelStatusCodes foundCode = userService.registerUser(mockUser);
+        when(userRepository.findByName(any())).thenReturn(new User(name, email, password));
 
-        assertEquals(foundCode, UserModelStatusCodes.USER_EXISTS);
+        UserModelStatusCodes foundCode = userService.verifyUser(mockUser);
+
+        assertEquals(UserModelStatusCodes.USER_LOGGED_IN, foundCode);
     }
 
     /**
-     * Testing login implementation
-     * for happy-day scenario user is registered
+     * for users name is not registered
      */
     @Test
-    public void whenUserIsRegistered_thenLoggedHim() {
+    public void whenUserIsNotRegistered_thenReturnMSG() {
 
-        Mockito.when(userRepository.findByName(mockUser.getName())).thenReturn(mockUser);
+        when(userRepository.findByName(any())).thenReturn(null);
 
-        String name = "test";
-        UserModelStatusCodes foundCode = userService.verifyUser(new User(name, ""));
+        UserModelStatusCodes foundCode = userService.verifyUser(mockUser);
 
-        assertEquals(foundCode, UserModelStatusCodes.USER_LOGGED_IN);
+        assertEquals(UserModelStatusCodes.USER_LOGIN_FAILED, foundCode);
     }
 
     /**
-     * Testing login implementation
-     * for users name is not registered
+     * for scenario when user has wrong password
      */
     @Test
-    public void whenUserIsNotRegistered_thenReturnMSG() {
+    public void whenUserHasWrongPassword_thenSendERROR_MSG() {
+        String name = mockUser.getName();
+        String password = "test";
+        String email = mockUser.getEmail();
+
+        when(userRepository.findByName(any())).thenReturn(new User(name, email, password));
+
+        UserModelStatusCodes foundCode = userService.verifyUser(mockUser);
+
+        assertEquals(UserModelStatusCodes.USER_LOGIN_FAILED, foundCode);
+    }
+
+
+
+
+
+    /* <-------- HASH TESTING --------> */
+    /**
+     * for happy-day scenario user is registered
+     */
+    @Test
+    public void Hash_test() {
+        String hash = "c63293087805fc0e63564b1f389a85de00a369b01f3b4b0d0f3a949f565d2765";
 
-        //Mockito.when(userRepository.findByName(mockUser.getName())).thenReturn(mockUser);
+        UserServiceImpl userService1 = new UserServiceImpl();
 
-        String name = "notest";
-        UserModelStatusCodes foundCode = userService.verifyUser(new User(name, ""));
+        String foundCode = userService1.hashPassword(mockUser.getPassword());
 
-        assertEquals(foundCode, UserModelStatusCodes.USER_LOGIN_FAILED);
+        assertEquals(hash.toUpperCase(), foundCode);
     }
 
 }
