package unitTest; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.Random; import java.util.function.Function; import java.util.stream.Stream; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.api.function.ThrowingConsumer; import exceptions.*; import project.Auction; import project.Item; import project.User; public class UserUnitTest { /* @Test public void loginTest() throws UsernameEmailEmptyException, PasswordInvalidException, MailInvalidException, LoginInvalidException { String username = "mario", password = "password", email = "test@gmail.com"; User u = new User(); u.setUsername(username); u.setEmail(email); u.setPassword(password); assertTrue(User.login(username, email, password)); assertThrows(LoginInvalidException.class, () -> { User.login(username, email, "wrong password"); }); } @TestFactory public Collection<DynamicTest> loginAcceptanceTest() { ArrayList<String> username = new ArrayList<String>(Arrays.asList("", "", "mario", "mario", "")); ArrayList<String> email = new ArrayList<String>( Arrays.asList("", "an.gmail.it", "mario@gmail.com", "", "mario@gmail.com")); ArrayList<String> password = new ArrayList<String>( Arrays.asList("test", "test", "", "wrong password", "wrong password")); ArrayList<String> errorMessages = new ArrayList<String>(Arrays.asList( "Error: you should provide an username or a password", "Error: email not in the right format", "Error: password blank", "Error: login invalid", "Error: login invalid")); ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("username and mail empty", "wrong mail format", "password empty", "login invalid with username", "login invalid with email")); ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>( Arrays.asList(UsernameEmailEmptyException.class, MailInvalidException.class, PasswordInvalidException.class, LoginInvalidException.class, LoginInvalidException.class)); Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>(); for (int i = 0; i < username.size(); i++) { String us = username.get(i); String em = email.get(i); String pw = password.get(i); String err = errorMessages.get(i); Executable exec = () -> assertThrows(exceptions.get(i), User.login(us, em, pw)); DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec); dynamicTests.add(dTest); } return dynamicTests; } */ }