<commit_before>

import static org.junit.Assert.*;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import ge.edu.freeuni.sdp.xo.login.LoginInformation;
import ge.edu.freeuni.sdp.xo.login.LoginService;
import ge.edu.freeuni.sdp.xo.login.Token;
import ge.edu.freeuni.sdp.xo.login.UserInformation;
import ge.edu.freeuni.sdp.xo.login.UserName;
import org.junit.Test;
import org.mockito.Mockito;

public class LoginServiceTest {
	
	@Test
	public void testLoginRegisteredUser() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = "<PASSWORD>";
		Mockito.when(userInfo.toString()).thenReturn("sandro, blabla");
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token.token, "00000");
	}
	

	@Test(expected=WebApplicationException.class)
	public void testLoginUserPasswordNull() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = null;
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserUsernameNull() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = null;
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserPasswordIncorrect() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserUsernameIncorrect() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro1";
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}

	@Test
	public void testGetUserByTokenRegistered() {
		LoginService loginService = new LoginService();
		UserName userName = Mockito.mock(UserName.class);
		userName = loginService.getUserByToken("00000");
		assertEquals(userName.username, "sandro");
	}

	@Test(expected=WebApplicationException.class)
	public void testGetUserByTokenNotRegistered() {
		LoginService loginService = new LoginService();
		UserName userName = Mockito.mock(UserName.class);
		userName = loginService.getUserByToken("00001");
		assertEquals(userName, null);
	}
	
	@Test
	public void testCreateUser() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
	}
	
	@Test
	public void testCreateUserUsernameNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = null;
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}
	
	@Test
	public void testCreateUserPasswordNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = <PASSWORD>;
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}
	
	@Test
	public void testCreateUserEmailNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = null;
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}

	@Test
	public void testGetUserRegistered() {
		LoginService loginService = new LoginService();
		UserInformation userInfo = Mockito.mock(UserInformation.class);
		userInfo = loginService.getUser("anna");
		assertEquals(userInfo.username, "anna");
		assertEquals(userInfo.password, "<PASSWORD>");
		assertEquals(userInfo.email, "<EMAIL>");
	}
	
	@Test(expected=WebApplicationException.class)
	public void testGetUserNotRegistered() {
		LoginService loginService = new LoginService();
		UserInformation userInfo = Mockito.mock(UserInformation.class);
		userInfo = loginService.getUser("Giorgi");
		assertEquals(userInfo, null);
	}

}<commit_msg>Added tests<commit_after>

import static org.junit.Assert.*;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import ge.edu.freeuni.sdp.xo.login.LoginInformation;
import ge.edu.freeuni.sdp.xo.login.LoginService;
import ge.edu.freeuni.sdp.xo.login.Token;
import ge.edu.freeuni.sdp.xo.login.UserInformation;
import ge.edu.freeuni.sdp.xo.login.UserName;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.mockito.Mockito;

public class LoginServiceTest extends JerseyTest{
	
	@Override
	 protected Application configure() {
		 return new ResourceConfig(LoginService.class);
	 }
	
	@Test
	public void testLoginRegisteredUser(){
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = "<PASSWORD>";
		Mockito.when(userInfo.toString()).thenReturn("sandro, blabla");
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token.token, "00000");
	}
	
	@Test
	public void testLoginRegisteredUser200Expected(){
		
		LoginInformation userInfo = new LoginInformation();
		userInfo.username = "sandro";
		userInfo.password = "<PASSWORD>";
		Mockito.when(userInfo.toString()).thenReturn("sandro, blabla");
	}

	@Test(expected=WebApplicationException.class)
	public void testLoginUserPasswordNull() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = <PASSWORD>;
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserUsernameNull() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = null;
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserPasswordIncorrect() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro";
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}
	
	@Test(expected=WebApplicationException.class)
	public void testLoginUserUsernameIncorrect() {
		LoginService loginService = new LoginService();
		LoginInformation userInfo = Mockito.mock(LoginInformation.class);
		userInfo.username = "sandro1";
		userInfo.password = "<PASSWORD>";
		Token token = Mockito.mock(Token.class);
		token = loginService.loginUser(userInfo);
		assertEquals(token, null);
	}

	@Test
	public void testGetUserByTokenRegistered() {
		LoginService loginService = new LoginService();
		UserName userName = Mockito.mock(UserName.class);
		userName = loginService.getUserByToken("00000");
		assertEquals(userName.username, "sandro");
	}
	
	@Test
	public void testGetUserByToken200Expected() {
		Response actual = target("/login/00000").request().get();
		assertEquals(Response.Status.OK.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testGetUserByToken404Expected() {
		Response actual = target("/login/00001").request().get();
		assertEquals(Response.Status.NOT_FOUND.getStatusCode(), actual.getStatus());
	}

	@Test(expected=WebApplicationException.class)
	public void testGetUserByTokenNotRegistered() {
		LoginService loginService = new LoginService();
		UserName userName = Mockito.mock(UserName.class);
		userName = loginService.getUserByToken("00001");
		assertEquals(userName, null);
	}
	
	@Test
	public void testCreateUser() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
	}
	
	@Test
	public void testCreateUserUsernameNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = null;
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}
	
	@Test
	public void testCreateUserPasswordNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = <PASSWORD>;
		user.email = "<EMAIL>";
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}
	
	@Test
	public void testCreateUserEmailNull() {
		LoginService loginService = new LoginService();
		UserInformation user = Mockito.mock(UserInformation.class);
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = null;
		Response response = Mockito.mock(Response.class);
		response = loginService.createUser(user);
		assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
	}
	
	@Test
	public void testCreateUser201Expected() {
		UserInformation user = new UserInformation();
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
        Response actual = target("/login/users").request().post(Entity.entity(user, MediaType.APPLICATION_JSON_TYPE));
        assertEquals(Response.Status.CREATED.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testCreateUserEmailNull404Expected() {
		UserInformation user = new UserInformation();
		user.username = "Giorgi";
		user.password = "<PASSWORD>";
		user.email = null;
        Response actual = target("/login/users").request().post(Entity.entity(user, MediaType.APPLICATION_JSON_TYPE));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testCreateUserPasswordNull404Expected() {
		UserInformation user = new UserInformation();
		user.username = "Giorgi";
		user.password = <PASSWORD>;
		user.email = "<EMAIL>";
        Response actual = target("/login/users").request().post(Entity.entity(user, MediaType.APPLICATION_JSON_TYPE));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testCreateUserNameNull404Expected() {
		UserInformation user = new UserInformation();
		user.username = null;
		user.password = "<PASSWORD>";
		user.email = "<EMAIL>";
        Response actual = target("/login/users").request().post(Entity.entity(user, MediaType.APPLICATION_JSON_TYPE));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testGetUserRegistered() {
		LoginService loginService = new LoginService();
		UserInformation userInfo = Mockito.mock(UserInformation.class);
		userInfo = loginService.getUser("anna");
		assertEquals(userInfo.username, "anna");
		assertEquals(userInfo.password, "<PASSWORD>");
		assertEquals(userInfo.email, "<EMAIL>");
	}
	
	@Test(expected=WebApplicationException.class)
	public void testGetUserNotRegistered() {
		LoginService loginService = new LoginService();
		UserInformation userInfo = Mockito.mock(UserInformation.class);
		userInfo = loginService.getUser("Giorgi");
		assertEquals(userInfo, null);
	}
	
	@Test
	public void testGetUserRegistered200Expected(){
		Response actual = target("/login/users/anna").request().get();
		assertEquals(Response.Status.OK.getStatusCode(), actual.getStatus());
	}
	
	@Test
	public void testGetUserNotRegistered404Expected(){
		Response actual = target("/login/users/giorgi").request().get();
		assertEquals(Response.Status.NOT_FOUND.getStatusCode(), actual.getStatus());
	}
	

}
{'fraction_non_alphanumeric': 0.12617743702081052, 'fraction_numerical': 0.005038335158817087, 'mean_word_length': 5.658240155566359, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2198370', 'n_tokens_mistral': 4292, 'n_tokens_neox': 3973, 'n_words': 744}