Browse Source

Account reset password method

feature-pr-AccountClass
Sona Markosyan 3 years ago
parent
commit
15d6b2c3ed
  1. 55
      src/main/java/hs/fulda/de/ci/exam/project/Account.java
  2. 20
      src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java

55
src/main/java/hs/fulda/de/ci/exam/project/Account.java

@ -0,0 +1,55 @@
package hs.fulda.de.ci.exam.project;
public class Account {
public Account(String id, String password, AccountStatus status) {
this.id = id;
this.password = password;
this.status = status;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public AccountStatus getStatus() {
return status;
}
public void setStatus(AccountStatus status) {
this.status = status;
}
public enum AccountStatus {
ACTIVE,
CLOSED,
CANCELED,
BLACKLISTED,
BLOCKED
}
private String id;
private String password;
private AccountStatus status;
public boolean resetPassword(String new_password){
if(status == AccountStatus.ACTIVE){
this.password = new_password;
}
return false;
}
}

20
src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java

@ -0,0 +1,20 @@
package hs.fulda.de.ci.exam.project;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class AccountTest {
@Test
void test_resetPassword(){
Account account1 = new Account("123", "password", Account.AccountStatus.ACTIVE);
Account account2 = new Account("453", "notactive", Account.AccountStatus.CANCELED);
account1.resetPassword("newpass");
account2.resetPassword("notgood");
assertEquals("newpass", account1.getPassword(),"Password successfully changed.");
assertEquals("notactive", account2.getPassword(),"Activate your account to change your password");
}
}
Loading…
Cancel
Save