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
34 changes: 34 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Domain Model

## User Stories
```
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.
```

| Method | Member | Scenario | Return |
|-----------------------------------|------------------------------------------------|---------------------|-----------------------|
| Account(email, password, enabled) | String email, String password, Boolean enabled | | |
| getEmail() | | | |
| getPassword() | | | |
| setEmail() | | | |
| setPassword() | | | |
| getStatus() | | | |
| setStatus() | | | |
| validatePassword() | String password | valid password | "valid password" |
| | | invalid password | "invalid password" |
| validateEmail() | String email | valid email | "valid email" |
| | | invalid email | "invalid email" |
| activeAccount() | Boolean enabled | account is disabled | "Account is disabled" |
| | | Account is enabled | "account is enabled" |
72 changes: 72 additions & 0 deletions src/main/java/com/booleanuk/core/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.booleanuk.core;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Account {
private String email;
private String password;
private Boolean enabled;

public String getEmail() {
return email;
}

public void setEmail(String email) {
validateEmail(email);
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
validatePassword(password);
this.password = password;
}

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public Account(String email, String password) {
if (validateEmail(email)){
this.email = email;
}
if (validatePassword(password)){
this.password = password;
}
this.enabled = false;
}
private Boolean validateEmail(String email){
Pattern pattern = Pattern.compile("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$");
Matcher matcher = pattern.matcher(email);
if (matcher.matches()) {
System.out.println("Valid email");
return true;
}
System.out.println("Invalid email");
return false;
}
private Boolean validatePassword(String password){
Pattern pattern = Pattern.compile("^.{8,}$");
Matcher matcher = pattern.matcher(password);
if (matcher.matches()) {
System.out.println("Valid password");
return true;
}
System.out.println("Invaldi password");
return false;
}
private String activeAccount(){
if (getEnabled()){
return "Account is enabled";
}
return "Account is disabled";
}
}
14 changes: 9 additions & 5 deletions src/main/java/com/booleanuk/core/TodoItem.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
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;
this.detail = detail;
this.status = status;
}

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

public String getStatus() {
return this.status;
}
public String getDetail(){
return this.detail;
}
public String getTitle(){
return this.title;
}
}
40 changes: 40 additions & 0 deletions src/test/java/com/booleanuk/core/AccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.booleanuk.core;

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

import static org.junit.jupiter.api.Assertions.*;

class AccountTest {

@Test
void getEmail() {
Account account = new Account("noe@mail.com","kalskeoskdfne");
Assertions.assertEquals("noe@mail.com", account.getEmail());
}

@Test
void setEmail() {
Account account = new Account("noe@mail.com","kalskeoskdfne");
account.setEmail("annet@mail.com");
Assertions.assertEquals("annet@mail.com", account.getEmail());
}
@Test
void getPassword() {
Account account = new Account("noe@mail.com","kalskeoskdfne");
Assertions.assertEquals("kalskeoskdfne", account.getPassword());
}
@Test
void setPassword() {
Account account = new Account("noe@mail.com","kalskeoskdfne");
account.setPassword("sadøjslafnkdas");
Assertions.assertEquals("sadøjslafnkdas", account.getPassword());
}
@Test
void getEnabled() {
Account account = new Account("noe@mail.com","kalskeoskdfne");
Assertions.assertFalse(account.getEnabled());
account.setEnabled(true);
Assertions.assertTrue(account.getEnabled());
}
}
23 changes: 22 additions & 1 deletion src/test/java/com/booleanuk/core/TodoItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,26 @@
import org.junit.jupiter.api.Test;

class TodoItemTest {

@Test
public void getTitleTest(){
TodoItem todoItem = new TodoItem("title1", "detail1", "OK");
Assertions.assertEquals("title1", todoItem.getTitle());
}
@Test
public void getDetailTest() {
TodoItem todoItem = new TodoItem("title1", "detail1", "OK");
Assertions.assertEquals("detail1", todoItem.getDetail());
}
@Test
public void getStatusTest() {
TodoItem todoItem = new TodoItem("title1", "detail1", "OK");
Assertions.assertEquals("OK", todoItem.getStatus());
}
@Test
public void setStatusTest() {
TodoItem todoItem = new TodoItem("title1", "detail1", "OK");
Assertions.assertEquals("OK", todoItem.getStatus());
todoItem.setStatus("Not OK");
Assertions.assertEquals("Not OK", todoItem.getStatus());
}
}