-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[W7][T11-2]Li Guanlong #40
base: master
Are you sure you want to change the base?
Changes from all commits
6da8dd0
66f5e50
50e1911
69cac52
c92738f
099be6d
199a0e2
06f5ea3
77eea70
305393a
52613e6
91d696e
9503dc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package seedu.addressbook.login; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class Login { | ||
|
||
private boolean loginStatus; | ||
|
||
public static final String LOGIN_PROMPT = "Please login in order to use the address book"; | ||
private static final String SUCCESS = "Login Success, loading..."; | ||
private static final String Invalid_USERNAME_OR_PASSWORD = "Invalid username or password, please try again"; | ||
private static final String Invalid_FORMAT = "Please input the correct login command: login username password"; | ||
private Map<String, String> accounts = new HashMap<String, String>(); | ||
|
||
|
||
public Login(){ | ||
this.loginStatus = false; | ||
this.accounts.put("guanlong", "12345"); | ||
this.accounts.put("doctorA", "doctorA"); | ||
} | ||
|
||
public void setLoginStatus(boolean newStatus){ | ||
this.loginStatus = newStatus; | ||
} | ||
|
||
public boolean getLoginStatus(){ | ||
return loginStatus; | ||
} | ||
|
||
public String checkLoginInfo(String userCommandText){ | ||
String[] accountInfo = userCommandText.split(" "); | ||
try { | ||
if (accountInfo.length == 3 && accountInfo[0].equals("login")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could apply some refactoring principles here. Multi-condition criteria could be extracted into booleans. |
||
if (accounts.containsKey(accountInfo[1]) && accounts.get(accountInfo[1]).equals(accountInfo[2])) { | ||
this.loginStatus = true; | ||
return SUCCESS; | ||
} | ||
else { | ||
return Invalid_USERNAME_OR_PASSWORD; | ||
} | ||
} | ||
else{ | ||
return Invalid_FORMAT; | ||
} | ||
} | ||
catch (Exception e){ | ||
return Invalid_FORMAT; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package seedu.addressbook.login; | ||
|
||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runners.Parameterized; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import seedu.addressbook.login.Login; | ||
|
||
public class LoginTest { | ||
|
||
private static final String SUCCESS = "Login Success, loading..."; | ||
private static final String Invalid_USERNAME_OR_PASSWORD = "Invalid username or password, please try again"; | ||
private static final String Invalid_FORMAT = "Please input the correct login command: login username password"; | ||
private Login login = new Login(); | ||
|
||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing header comment. All non-trivial methods should have java doc format header comments. |
||
public void setLoginStatus() { | ||
login.setLoginStatus(true); | ||
assertEquals(login.getLoginStatus(), true); | ||
} | ||
|
||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing header comment. All non-trivial methods should have java doc format header comments. |
||
public void getLoginStatus() { | ||
login.setLoginStatus(false); | ||
assertEquals(login.getLoginStatus(), false); | ||
} | ||
|
||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing header comment. All non-trivial methods should have java doc format header comments. |
||
public void checkLoginInfo() { | ||
final String input1 = "login guanlong 12345"; | ||
final String input2 = "some_random_string"; | ||
final String input3 = "login wrong_username wrong_password"; | ||
assertEquals(login.checkLoginInfo(input1), SUCCESS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job here, providing the positive and negative test cases. |
||
assertEquals(login.checkLoginInfo(input2), Invalid_FORMAT); | ||
assertEquals(login.checkLoginInfo(input3), Invalid_USERNAME_OR_PASSWORD); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing header comment. All non-trivial methods should have java doc format header comments.