diff --git a/domain-model.md b/domain-model.md
new file mode 100644
index 0000000..387ce2c
--- /dev/null
+++ b/domain-model.md
@@ -0,0 +1,50 @@
+As a system administrator,
+I want my users to have to create a user account with an email address and a password.
+
+| Class | Method | Variables | Scenario | Outcome |
+|----------------|---------------------------------------|------------------------------------------------------------------------------------|-----------------------|---------------------------------|
+| AccountManager | addAccount(String email, String pwrd) | String account,
String pwrd
Boolean active
ArrayList accountList | Account exists | Print error, return false |
+| | | | Account doesn't exist | Add to accountList, return true |
+
+
+
+I want them to receive an "invalid password" message if they provide a
+password less than 8 characters in length.
+
+| Class | Method | Variables | Scenario | Outcome |
+|----------------|---------------------------------------|------------------------------------------------------------------------------------|-------------------------|---------------------------------|
+| AccountManager | addAccount(String email, String pwrd) | String account,
String pwrd
Boolean active
ArrayList accountList | Invalid password length | Print error, return false |
+| | | | Valid password length | Add to accountList, return true |
+
+
+
+
+I want them to receive an "invalid email" message if they provide an email
+address without an @ symbol in it.
+
+| Class | Method | Variables | Scenario | Outcome |
+|----------------|---------------------------------------|------------------------------------------------------------------------------------|-----------------------|---------------------------------|
+| AccountManager | addAccount(String email, String pwrd) | String account,
String pwrd
Boolean active
ArrayList accountList | No "@" in email field | Print error, return false |
+| | | | Email contains a "@" | Add to accountList, return true |
+
+
+
+I want new accounts to be disabled by default until I manually set them as enabled.
+
+| Class | Method | Variables | Scenario | Outcome |
+|----------------|---------------------------------------|------------------------------------------------------------------------------------|--------------------------------|----------------------------------------------|
+| AccountManager | addAccount(String email, String pwrd) | String account,
String pwrd
Boolean active ArrayList accountList | Account is succesfully created | "Active" bool always set to false by default |
+
+
+
+I want users to know if they are able to log in or not based on whether their
+account is enabled or disabled.
+
+| Class | Method | Variables | Scenario | Outcome |
+|----------------|-----------|--------------------------------|----------------------------------------|--------------------------------------|
+| AccountManager | loginUser | ArrayList accountList | Email or Password wrong | Print error, return false |
+| | | | login correct, but account is disabled | Print account disabled, return false |
+| | | | login correct, account enabled | Print login success, return true |
+
+
+
diff --git a/src/main/java/com/booleanuk/core/Account.java b/src/main/java/com/booleanuk/core/Account.java
new file mode 100644
index 0000000..cb7a102
--- /dev/null
+++ b/src/main/java/com/booleanuk/core/Account.java
@@ -0,0 +1,38 @@
+package com.booleanuk.core;
+
+public class Account {
+
+ private Boolean active;
+ private String email;
+ private String password;
+
+ public Account(String email, String password) {
+ this.active = false;
+ this.email = email;
+ this.password = password;
+ }
+
+ public Boolean getActive() {
+ return active;
+ }
+
+ public void toggleActive() {
+ this.active = !active;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/src/main/java/com/booleanuk/core/AccountManager.java b/src/main/java/com/booleanuk/core/AccountManager.java
new file mode 100644
index 0000000..6522322
--- /dev/null
+++ b/src/main/java/com/booleanuk/core/AccountManager.java
@@ -0,0 +1,48 @@
+package com.booleanuk.core;
+
+import java.util.ArrayList;
+
+public class AccountManager {
+
+ private ArrayList accountList;
+
+ public AccountManager(){
+ accountList = new ArrayList<>();
+ }
+
+ public Boolean addAccount(String email, String password){
+ if(!email.contains("@")){
+ System.out.println("Invalid Email doesn't contain @");
+ return false;
+ }else if (password.length() < 8){
+ System.out.println("Password not strong enough");
+ return false;
+ }
+ accountList.add(new Account(email, password));
+ System.out.println("Account successfully created");
+ return true;
+ }
+
+ public Boolean login(String email, String password){
+ for (Account account: accountList){
+ if (account.getEmail().equals(email) && account.getPassword().equals(password) && !account.getActive()){
+ System.out.println("ACCOUNT DISABLED");
+ return false;
+ }else if(account.getEmail().equals(email) && account.getPassword().equals(password)){
+ System.out.println("Login successful");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void toggleActive(String email){
+ for (Account a: accountList){
+ if(a.getEmail().equals(email)){
+ a.toggleActive();
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/booleanuk/core/TodoItem.java b/src/main/java/com/booleanuk/core/TodoItem.java
index 655d825..059ae41 100644
--- a/src/main/java/com/booleanuk/core/TodoItem.java
+++ b/src/main/java/com/booleanuk/core/TodoItem.java
@@ -1,9 +1,9 @@
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 TodoItem(String title, String detail, String status) {
this.title = title;
@@ -18,4 +18,21 @@ public void setStatus(String status) {
public String getStatus() {
return this.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;
+ }
+
}
diff --git a/src/test/java/com/booleanuk/core/AccountManagerTest.java b/src/test/java/com/booleanuk/core/AccountManagerTest.java
new file mode 100644
index 0000000..bf974f5
--- /dev/null
+++ b/src/test/java/com/booleanuk/core/AccountManagerTest.java
@@ -0,0 +1,38 @@
+package com.booleanuk.core;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class AccountManagerTest {
+
+ @Test
+ void createUserTest() {
+ AccountManager acm = new AccountManager();
+
+ //Test if it can be compelted
+ Assertions.assertTrue(acm.addAccount("jostein@gmail.com", "12345678"));
+ //Test if password length is good enough
+ Assertions.assertFalse(acm.addAccount("Jostein@gmail.com", "123"));
+ //Test for @ in email
+ Assertions.assertFalse(acm.addAccount("Josteingmail.com", "12345678"));
+
+ }
+
+ @Test
+ void loginTest(){
+ AccountManager acm = new AccountManager();
+ acm.addAccount("jostein@gmail.com", "12345678");
+ //set account to active
+ acm.toggleActive("jostein@gmail.com");
+
+ Assertions.assertTrue(acm.login("jostein@gmail.com", "12345678"));
+
+ acm.toggleActive("jostein@gmail.com");
+ //Test for disabled account
+ Assertions.assertFalse(acm.login("jostein@gmail.com", "12345678"));
+
+
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/booleanuk/core/TodoItemTest.java b/src/test/java/com/booleanuk/core/TodoItemTest.java
index 095af82..c3be71b 100644
--- a/src/test/java/com/booleanuk/core/TodoItemTest.java
+++ b/src/test/java/com/booleanuk/core/TodoItemTest.java
@@ -3,6 +3,52 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
class TodoItemTest {
-}
+ @Test
+ void setStatus() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+ todoItem.setStatus("Incomplete");
+
+ Assertions.assertEquals("Incomplete", todoItem.getStatus());
+ }
+
+ @Test
+ void getStatus() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+
+ Assertions.assertEquals("Complete", todoItem.getStatus());
+ }
+
+ @Test
+ void getTitle() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+
+
+ Assertions.assertEquals("My title", todoItem.getTitle());
+ }
+
+ @Test
+ void setTitle() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+ todoItem.setTitle("New title");
+
+ Assertions.assertEquals("New title", todoItem.getTitle());
+ }
+
+ @Test
+ void getDetail() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+
+ Assertions.assertEquals("My details", todoItem.getDetail());
+ }
+
+ @Test
+ void setDetail() {
+ TodoItem todoItem = new TodoItem("My title", "My details", "Complete");
+ todoItem.setDetail("New details");
+
+ Assertions.assertEquals("New details", todoItem.getDetail());
+ }
+}
\ No newline at end of file