From f5ab6e74fbffed991b927ded6401bd91cfffb324 Mon Sep 17 00:00:00 2001 From: Robin Kaastrup Date: Thu, 18 Jan 2024 09:47:30 +0100 Subject: [PATCH 1/3] Added tests and implementation --- .../java/com/booleanuk/core/TodoItem.java | 30 ++++++++++++++++-- .../java/com/booleanuk/core/TodoItemTest.java | 31 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/booleanuk/core/TodoItem.java b/src/main/java/com/booleanuk/core/TodoItem.java index 655d825..3a51365 100644 --- a/src/main/java/com/booleanuk/core/TodoItem.java +++ b/src/main/java/com/booleanuk/core/TodoItem.java @@ -1,9 +1,29 @@ 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; @@ -11,6 +31,8 @@ public TodoItem(String title, String detail, String status) { this.status = status; } + + public void setStatus(String status) { this.status = status; } @@ -18,4 +40,6 @@ public void setStatus(String status) { public String getStatus() { return this.status; } + + } diff --git a/src/test/java/com/booleanuk/core/TodoItemTest.java b/src/test/java/com/booleanuk/core/TodoItemTest.java index 095af82..8ead5fb 100644 --- a/src/test/java/com/booleanuk/core/TodoItemTest.java +++ b/src/test/java/com/booleanuk/core/TodoItemTest.java @@ -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()); + + } + + + + + } From 2af4f619252805e263fe5d472eb7d614bb49c5ce Mon Sep 17 00:00:00 2001 From: Robin Kaastrup Date: Thu, 18 Jan 2024 11:00:25 +0100 Subject: [PATCH 2/3] Added tests to UserAccountTest based on domain-model.md --- domain-model.md | 36 +++++++++++ .../java/com/booleanuk/core/TodoItem.java | 4 -- .../java/com/booleanuk/core/UserAccount.java | 17 +++++ .../com/booleanuk/core/UserAccountTest.java | 62 +++++++++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 domain-model.md create mode 100644 src/main/java/com/booleanuk/core/UserAccount.java create mode 100644 src/test/java/com/booleanuk/core/UserAccountTest.java diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 0000000..959ab4a --- /dev/null +++ b/domain-model.md @@ -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() | | | diff --git a/src/main/java/com/booleanuk/core/TodoItem.java b/src/main/java/com/booleanuk/core/TodoItem.java index 3a51365..70db1d2 100644 --- a/src/main/java/com/booleanuk/core/TodoItem.java +++ b/src/main/java/com/booleanuk/core/TodoItem.java @@ -2,10 +2,6 @@ public class TodoItem { private String title; - - - - private String detail; private String status; diff --git a/src/main/java/com/booleanuk/core/UserAccount.java b/src/main/java/com/booleanuk/core/UserAccount.java new file mode 100644 index 0000000..28d5cd4 --- /dev/null +++ b/src/main/java/com/booleanuk/core/UserAccount.java @@ -0,0 +1,17 @@ +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; + } + +} diff --git a/src/test/java/com/booleanuk/core/UserAccountTest.java b/src/test/java/com/booleanuk/core/UserAccountTest.java new file mode 100644 index 0000000..a3efd0f --- /dev/null +++ b/src/test/java/com/booleanuk/core/UserAccountTest.java @@ -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()); + + } + + +} From f594d9836a51cc344f7e19b256127a17ea8076c3 Mon Sep 17 00:00:00 2001 From: Robin Kaastrup Date: Thu, 18 Jan 2024 11:26:34 +0100 Subject: [PATCH 3/3] Implemented methods in UserAccount.java based on tests and domain modell. Last test still failing --- .../java/com/booleanuk/core/UserAccount.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/com/booleanuk/core/UserAccount.java b/src/main/java/com/booleanuk/core/UserAccount.java index 28d5cd4..abcd241 100644 --- a/src/main/java/com/booleanuk/core/UserAccount.java +++ b/src/main/java/com/booleanuk/core/UserAccount.java @@ -14,4 +14,51 @@ public UserAccount(String email, String password) { 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; + } + }