Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

```
As a system administrator,
I want my users to have to create a user account with an email address and a password.

I want them to receive an "invalid password" message if they provide a
password less than 8 characters in length.

I want them to receive an "invalid email" message if they provide an email
address without an @ symbol in it.

I want new accounts to be disabled by default until I manually set them as enabled.

I want users to know if they are able to log in or not based on whether their
account is enabled or disabled.
```

| Class | Fields | Methods | Situation | Output / Response |
|-------------|------------------|-------------------------------------------|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
| UserAccount | String password | | | |
| | String email | | | |
| | boolean enabled | | | |
| | boolean loggedIn | | | |
| | | void enableAccount() | The system administrator wants to enable an account | The field enabled is set to true |
| | | void disableAccount() | The system administrator wants to disable an account | The field enabled is set to false |
| | | boolean getEnabled() | See if an account is enabled | returns enabled |
| | | void logIn(String email, String password) | The user wishes to log into their account with correct password and email | Set field LoggedIn to true |
| | | | The user wishes to log into their account with incorrect password or email | Set field LoggedIn to false |
| | | | The user wishes to log into their account without the account being enabled | Set field loggedIn to false regardless of password and email provided |
| | | boolean isLoggedIn() | Check if user is logged in | Returns true if user is logged into account |
| | | setEmail(String email) | email lacks @ symbol | the user is shown a message "Invalid Email" |
| | | | email has @ symbol | new email is set |
| | | String getEmail() | | |
| | | void setPassword(String password) | password is given with less than 8 characters | Don't set new password |
| | | | password is given with 8 or more characters | Set new this.password to password |
| | | String getPassword() | | |
26 changes: 23 additions & 3 deletions src/main/java/com/booleanuk/core/TodoItem.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
package com.booleanuk.core;

public class TodoItem {
public String title;
public String detail;
public String status;
private String title;
private String detail;
private String status;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDetail() {
return detail;
}

public void setDetail(String detail) {
this.detail = detail;
}

public TodoItem(String title, String detail, String status) {
this.title = title;
this.detail = detail;
this.status = status;
}



public void setStatus(String status) {
this.status = status;
}

public String getStatus() {
return this.status;
}


}
64 changes: 64 additions & 0 deletions src/main/java/com/booleanuk/core/UserAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.booleanuk.core;

public class UserAccount {

private String email;
private String password;
private boolean enabled;
private boolean loggedIn;

public UserAccount(String email, String password) {
this.email = email;
this.password = password;
this.enabled = false;
this.loggedIn = false;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
if(email.contains("@")) {
this.email = email;
}
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
if(password.length() >= 8) {
this.password = password;
}
}

public void enableAccount() {
this.enabled = true;
}

public void disableAccount() {
this.enabled = false;
}

public boolean getEnabled() {
return this.enabled;
}

public void logIn(String email, String password) {
if(!this.loggedIn) {
if (this.enabled) {
if(this.email.equals(email) && this.password.equals(password)) {
this.loggedIn = true;
}
}
this.loggedIn = false;
}
}

public boolean isLoggedIn() {
return this.loggedIn;
}

}
31 changes: 31 additions & 0 deletions src/test/java/com/booleanuk/core/TodoItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,35 @@

class TodoItemTest {

@Test
public void setGetStatusTest() {
TodoItem todoItem = new TodoItem("Wash dishes", "Put in sink, turn on faucet, scrub", "incomplete");
Assertions.assertEquals("Incomplete", todoItem.getStatus());
todoItem.setStatus("Complete");
Assertions.assertEquals("Complete", todoItem.getStatus());

}

@Test
public void setGetTitleTest() {
TodoItem todoItem = new TodoItem("Wash dishes", "Put in sink, turn on faucet, scrub", "incomplete");
Assertions.assertEquals("Wash dishes", todoItem.getTitle());
todoItem.setTitle("Make eggs");
Assertions.assertEquals("Make eggs", todoItem.getTitle());

}

@Test
public void setGetDetailTest() {
TodoItem todoItem = new TodoItem("Wash dishes", "Put in sink, turn on faucet, scrub", "incomplete");
Assertions.assertEquals("Put in sink, turn on faucet, scrub", todoItem.getDetail());
todoItem.setDetail("Be Chicken, lay egg");
Assertions.assertEquals("Be Chicken, lay egg", todoItem.getDetail());

}





}
62 changes: 62 additions & 0 deletions src/test/java/com/booleanuk/core/UserAccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class UserAccountTest {

@Test
public void getSetEmailTest() {
UserAccount userAccount = new UserAccount("test@test.test", "tEst!@#");
Assertions.assertEquals("test@test.test", userAccount.getEmail());
userAccount.setEmail("tested@tested.tested");
Assertions.assertEquals("tested@tested.tested", userAccount.getEmail());
userAccount.setEmail("test");
Assertions.assertEquals("tested@tested.tested", userAccount.getEmail());
}

@Test
public void getSetPasswordTest() {
UserAccount userAccount = new UserAccount("test@test.test", "tEst!@#");
Assertions.assertEquals("tEst!@#", userAccount.getPassword());
userAccount.setPassword("Gavilar!@#");
Assertions.assertEquals("Gavilar!@#", userAccount.getPassword());
userAccount.setPassword("kk");
Assertions.assertEquals("Gavilar!@#", userAccount.getPassword());

}

@Test
public void enableAccountTest() {
UserAccount userAccount = new UserAccount("test@test.test", "tEst!@#");
Assertions.assertFalse(userAccount.getEnabled());
userAccount.enableAccount();
Assertions.assertTrue(userAccount.getEnabled());

}

@Test
public void disableAccountTest() {
UserAccount userAccount = new UserAccount("test@test.test", "tEst!@#");
userAccount.enableAccount();
Assertions.assertTrue(userAccount.getEnabled());
userAccount.disableAccount();
Assertions.assertFalse(userAccount.getEnabled());

}

@Test
public void LogInTest() {
UserAccount userAccount = new UserAccount("test@test.test", "tEst!@#");
userAccount.logIn("test@test.test", "tEst!@#");
Assertions.assertFalse(userAccount.isLoggedIn());
userAccount.logIn("@test.test", "tE!@#");
Assertions.assertFalse(userAccount.isLoggedIn());
userAccount.enableAccount();
userAccount.logIn("test@test.test", "tEst!@#");
Assertions.assertTrue(userAccount.isLoggedIn());

}


}