Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhavan7 committed Dec 2, 2022
1 parent aa560c5 commit d07586b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/main/java/screens/login_screen/UserLoginUI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package screens.login_screen;
import use_cases.user_login_use_cases.UserLoginInputBoundary;
import use_cases.user_login_use_cases.UserLoginPresenter;
import use_cases.user_registration_use_cases.UserVerificationOutputBoundary;

import javax.swing.*;
Expand All @@ -9,11 +9,11 @@
/** This is the screen on which the user enters his credentials in order to login **/
public class UserLoginUI implements ActionListener, UserVerificationOutputBoundary {

private final UserLoginInputBoundary loginInteractor;
private final UserLoginPresenter loginInteractor;
JTextField credentialText;
JPasswordField passwordText;

public UserLoginUI(UserLoginInputBoundary loginInteractor){
public UserLoginUI(UserLoginPresenter loginInteractor){
this.loginInteractor = loginInteractor;
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import data_access.Database;
import data_access.UserDatabase;
import screens.login_screen.UserLoginUI;
import use_cases.user_login_use_cases.UserLoginInputBoundary;
import use_cases.user_login_use_cases.UserLoginInteractor;
import use_cases.user_login_use_cases.UserLoginPresenter;
import use_cases.user_registration_use_cases.*;

import javax.swing.*;
Expand All @@ -13,7 +12,7 @@

/** This is screen on which the User enters his credentials in order to login**/
public class UserRegistrationUI implements ActionListener, userRegCredentialsRetriever {
private final UserExistsInputBoundary verifyUser;
private final UserExistsPresenter verifyUser;
private JTextField usernameText;
private JTextField passwordText;
private JTextField emailText;
Expand All @@ -23,7 +22,7 @@ public class UserRegistrationUI implements ActionListener, userRegCredentialsRet
*/
private JTextField deliveryText;

public UserRegistrationUI(UserExistsInputBoundary existsInputBoundary) {
public UserRegistrationUI(UserExistsPresenter existsInputBoundary) {
this.verifyUser = existsInputBoundary;
}
/**
Expand Down Expand Up @@ -85,11 +84,11 @@ public void getUserCredentials(){

public static void main(String[] args){
Database testDB = new UserDatabase(new File("newAccounts2"));
UserLoginInputBoundary userLoginInteractor = new UserLoginInteractor(testDB);
UserLoginPresenter userLoginInteractor = new UserLoginPresenter(testDB);
UserVerificationOutputBoundary loginUI = new UserLoginUI(userLoginInteractor);
UserVerificationInputBoundary verificationInteractor = new UserVerificationInteractor(testDB, loginUI);
UserVerificationPresenter verificationInteractor = new UserVerificationPresenter(testDB, loginUI);
UserExistsOutputBoundary verificationScreen = new UserVerificationScreen(verificationInteractor);
UserExistsInputBoundary existsInteractor = new UserExistsInteractor(testDB, verificationScreen, new verificationMethodFactory());
UserExistsPresenter existsInteractor = new UserExistsPresenter(testDB, verificationScreen, new verificationMethodFactory());
UserRegistrationUI testUI = new UserRegistrationUI(existsInteractor);
testUI.getUserCredentials();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* */
public class UserVerificationScreen implements UserExistsOutputBoundary, ActionListener {
private final JTextField verText = new JTextField(20);
private final UserVerificationInputBoundary verificationInputBoundary;
private final UserVerificationPresenter verificationInputBoundary;
private int code;
private String username;
private String password;
private String email;

public UserVerificationScreen(UserVerificationInputBoundary verificationInputBoundary){
public UserVerificationScreen(UserVerificationPresenter verificationInputBoundary){
this.verificationInputBoundary = verificationInputBoundary;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

import data_access.Database;
import entities.user_entities.User;
import use_cases.user_registration_use_cases.UserVerificationOutputBoundary;

public class UserLoginInteractor implements UserLoginInputBoundary{
public class UserLoginPresenter {
private String username;
private String password;
private User user;
Database database;
public UserLoginInteractor(Database database){
public UserLoginPresenter(Database database){
this.database = database;
}

@Override
public void tryLogin() {
try{
//TODO: issues here with serialization
//TODO: issues here with serialization, and dependency inversion
user = database.getUser(username);
if(user.PasswordMatch(this.password)){
user.login();
Expand All @@ -30,7 +28,6 @@ public void tryLogin() {

}

@Override
public void setLoginCredentials(String username, String password) {
this.username = username;
this.password = password;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* This is the class responsible for getting processing the input given by user, and either allowing verification,
* presenting the 'user exists' message, and sending the verification code, depending on the business logic
* */
public class UserExistsInteractor implements UserExistsInputBoundary{
public class UserExistsPresenter {
private final VerificationCodeDeliveryManager verCodeDeliveryManager;
Database database;
UserExistsOutputBoundary existsOutputBoundary;

public UserExistsInteractor(Database database, UserExistsOutputBoundary existsOutputBoundary, createMailMan mailMan){
public UserExistsPresenter(Database database, UserExistsOutputBoundary existsOutputBoundary, createMailMan mailMan){
this.database = database;
this.existsOutputBoundary = existsOutputBoundary;
//The responsibility of dealing with verification is passed onto this class
Expand All @@ -24,7 +24,7 @@ public UserExistsInteractor(Database database, UserExistsOutputBoundary existsOu
* @param email Email
* @param password Password
* */
@Override

public void register(String username, String password, String email) {
if(!database.UserExists(username, email)){
//This may need to change if verCodeDeliveryManager decides not to create integer codes.
Expand All @@ -41,7 +41,6 @@ public void register(String username, String password, String email) {
* Sets the verification stream given by the user, to send the code
* @param type The verification stream
* */
@Override
public void setCodeDeliveryMethod(String type) {
this.verCodeDeliveryManager.setMailMan(type);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import data_access.Database;

public class UserVerificationInteractor implements UserVerificationInputBoundary{
public class UserVerificationPresenter {
private final Database database;
private String username;
private String password;
Expand All @@ -12,7 +12,7 @@ public class UserVerificationInteractor implements UserVerificationInputBoundary

private int code;

public UserVerificationInteractor(Database database, UserVerificationOutputBoundary verificationOutputBoundary){
public UserVerificationPresenter(Database database, UserVerificationOutputBoundary verificationOutputBoundary){
this.database = database;
this.verificationOutputBoundary = verificationOutputBoundary;
}
Expand All @@ -21,7 +21,6 @@ public UserVerificationInteractor(Database database, UserVerificationOutputBound
* Else, it will present a message that verification is not possible
* @param code code inputted by the user
* */
@Override
public void verify(int code) {
System.out.println(this.code);
if(code == this.code){
Expand All @@ -35,7 +34,6 @@ public void verify(int code) {
/**
* Sets the code to compare for verification
* @param code verification code*/
@Override
public void setCode(int code) {
this.code = code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import use_cases.user_registration_use_cases.ISendVerificationCode;
import use_cases.user_registration_use_cases.UserExistsInteractor;
import use_cases.user_registration_use_cases.UserExistsPresenter;
import use_cases.user_registration_use_cases.UserExistsOutputBoundary;
import use_cases.user_registration_use_cases.createMailMan;

public class TestUserExistsInputBoundary {
public class TestUserExistsInteractor {
//Objects used for testing
// The below anonymous database is created to test cases where the user does not exist.
Database userDontExist = new Database() {
Expand Down Expand Up @@ -103,7 +103,7 @@ public ISendVerificationCode getVerificationMethod(String type) {
//In the first test, the user exists in the database, and we will set verStream1 as the verification method
@Test
public void userExistsInDatabase1(){
UserExistsInteractor uInteractor = new UserExistsInteractor(userExists,
UserExistsPresenter uInteractor = new UserExistsPresenter(userExists,
userExistsOutputBoundary, mailManFactory);
uInteractor.setCodeDeliveryMethod("0");
uInteractor.register("a", "b", "c");
Expand All @@ -116,7 +116,7 @@ public void userExistsInDatabase1(){
public void userExistsInDatabase2(){
TestOutputBoundary userExists2 = new TestOutputBoundary();
TestCreateMailMan createMailMan2 = new TestCreateMailMan();
UserExistsInteractor uInteractor2 = new UserExistsInteractor(userDontExist, userExists2, createMailMan2);
UserExistsPresenter uInteractor2 = new UserExistsPresenter(userDontExist, userExists2, createMailMan2);
uInteractor2.setCodeDeliveryMethod("1");
uInteractor2.register("a", "b", "c");
//The quantity below should be 213
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import entities.user_entities.User;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import use_cases.user_registration_use_cases.UserVerificationInteractor;
import use_cases.user_registration_use_cases.UserVerificationPresenter;
import use_cases.user_registration_use_cases.UserVerificationOutputBoundary;

public class TestUserVerificationInputBoundary {
public class TestUserVerificationInteractor {
private class testDatabase implements Database{
public int x;
@Override
Expand Down Expand Up @@ -48,7 +48,7 @@ public void cannotVerify() {
//The below test is to see if the verify function works in the case that the code is not right
@Test
public void testCodeNotRight(){
UserVerificationInteractor testInteractor = new UserVerificationInteractor(testDB, userVerificationOutputBdy);
UserVerificationPresenter testInteractor = new UserVerificationPresenter(testDB, userVerificationOutputBdy);

testInteractor.setCode(123);
testInteractor.setCredentials("a", "b", "c");
Expand All @@ -58,7 +58,7 @@ public void testCodeNotRight(){
//The below test is to see if the verify function works in the case that the code is right
@Test
public void testCodeRight(){
UserVerificationInteractor testInteractor = new UserVerificationInteractor(testDB, userVerificationOutputBdy);
UserVerificationPresenter testInteractor = new UserVerificationPresenter(testDB, userVerificationOutputBdy);

testInteractor.setCode(123);
testInteractor.setCredentials("a", "b", "c");
Expand Down

0 comments on commit d07586b

Please sign in to comment.