Skip to content
Snippets Groups Projects
Commit 1ea23658 authored by cristiano's avatar cristiano
Browse files

Merge branch 'UnitClassTesting' of gitlab.inf.unibz.it:TTST1920/clar into UnitClassTesting

parents 4d49e012 6fe576e7
No related branches found
No related tags found
No related merge requests found
Showing
with 153 additions and 22 deletions
public class Main {
public static void main(String[] args) {
String email = "usr@mail.com";
System.out.println(email.equals("usr@mail.com"));
}
}
......@@ -2,4 +2,10 @@ package exceptions;
public class LoginInvalidException extends Exception {
public LoginInvalidException() {
super("Error: login invalid");
}
}
......@@ -2,4 +2,8 @@ package exceptions;
public class MailInvalidException extends Exception {
public MailInvalidException() {
super("Error: email not in the right format");
}
}
......@@ -2,4 +2,8 @@ package exceptions;
public class PasswordInvalidException extends Exception {
public PasswordInvalidException() {
super("Error: password blank");
}
}
......@@ -2,4 +2,10 @@ package exceptions;
public class SSSInvalidException extends Exception {
public SSSInvalidException() {
super("prova");
}
}
......@@ -2,4 +2,8 @@ package exceptions;
public class UsernameEmailEmptyException extends Exception {
public UsernameEmailEmptyException() {
super("Error: you should provide an username or an email");
}
}
......@@ -2,6 +2,9 @@ package project;
import java.util.ArrayList;
import exceptions.LoginInvalidException;
import exceptions.MailInvalidException;
import exceptions.PasswordInvalidException;
import exceptions.UsernameEmailEmptyException;
public class User {
......@@ -19,16 +22,25 @@ public class User {
}
public User(String usernameInput, String mailInput, String passwordInput) {
username = usernameInput;
email = mailInput;
password = passwordInput;
this.id = idCounter++;
users.add(this);
}
public static User getInstance() {
User u = new User();
return u;
}
// *******************
// DA ERRORE!!!
// *******************
public static boolean login(String username, String email, String password) throws UsernameEmailEmptyException {
public static boolean login(String username, String email, String password)
throws UsernameEmailEmptyException, PasswordInvalidException, MailInvalidException, LoginInvalidException {
if (username.equals("") && email.equals("")) {
......@@ -38,24 +50,79 @@ public class User {
if (password.equals("")) {
System.err.println("Error: you should provide an username or a password");
throw new PasswordInvalidException();
} else if (!username.equals("")) {
User toCheck = null;
for (User u : users) {
} else if (username.equals("")) {
if (u.username.equals(username)) {
if (email.matches("\\S+@\\S+\\.\\w+")) {
toCheck = u;
}
}
if (toCheck == null) {
throw new LoginInvalidException();
} else {
System.err.println("Error: email not in the right format");
if (password.equals(toCheck.password)) {
return true;
} else {
throw new LoginInvalidException();
}
}
} else if (!email.equals("usr@mail.com")) {
throw new MailInvalidException();
} else {
User toCheck = null;
for (User u : users) {
if (u.email.equals(email)) {
toCheck = u;
}
}
if (toCheck == null) {
throw new LoginInvalidException();
} else {
if (password.equals(toCheck.password)) {
return true;
} else {
throw new LoginInvalidException();
}
}
}
}
return false;
}
......
package fitNesseFixture;
import project.User;
import exceptions.LoginInvalidException;
import exceptions.MailInvalidException;
import exceptions.PasswordInvalidException;
import exceptions.UsernameEmailEmptyException;
import project.Category;
......@@ -11,40 +14,65 @@ public class UserFixture {
private User u;
private double price, bidIncrement;
public boolean userLogin() {
public UserFixture(String usernameInput, String mailInput, String passwordInput) {
User u = new User(usernameInput, mailInput, passwordInput);
}
public String userLogin() {
u = User.getInstance();
try {
return u.login(username, email, password);
if (User.login(username, email, password)) {
return "Login worked!";
}
} catch (UsernameEmailEmptyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
} catch (PasswordInvalidException e) {
return e.getMessage();
} catch (MailInvalidException e) {
return e.getMessage();
} catch (LoginInvalidException e) {
return e.getMessage();
}
return false;
return null;
}
public boolean becomeSeller() {
u = User.getInstance();
return u.becomeSeller(ssn);
}
public boolean searchItem() {
u = User.getInstance();
return u.searchItem(title, Category.getCategory(category));
}
public boolean searchAuction() {
u = User.getInstance();
return u.searchAuction(startTime, endTime, price, bidIncrement, title, Category.getCategory(category));
}
public void setUsername(String username) {
this.username = username;
}
......@@ -64,6 +92,7 @@ public class UserFixture {
public void setU(User u) {
this.u = u;
}
public void setTitle(String title) {
this.title = title;
}
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment