Skip to content

Jostein Ruen #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
50 changes: 50 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -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, <br/>String pwrd<br/>Boolean active <br/>ArrayList<Account> 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, <br/>String pwrd<br/>Boolean active<br/> ArrayList<Account> 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, <br/>String pwrd<br/>Boolean active <br/>ArrayList<Account> 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, <br/>String pwrd<br/>Boolean active ArrayList<Account> 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<Account> 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 |



38 changes: 38 additions & 0 deletions src/main/java/com/booleanuk/core/Account.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/booleanuk/core/AccountManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class AccountManager {

private ArrayList<Account> 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();
}
}
}


}
23 changes: 20 additions & 3 deletions src/main/java/com/booleanuk/core/TodoItem.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

}
38 changes: 38 additions & 0 deletions src/test/java/com/booleanuk/core/AccountManagerTest.java
Original file line number Diff line number Diff line change
@@ -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("[email protected]", "12345678"));
//Test if password length is good enough
Assertions.assertFalse(acm.addAccount("[email protected]", "123"));
//Test for @ in email
Assertions.assertFalse(acm.addAccount("Josteingmail.com", "12345678"));

}

@Test
void loginTest(){
AccountManager acm = new AccountManager();
acm.addAccount("[email protected]", "12345678");
//set account to active
acm.toggleActive("[email protected]");

Assertions.assertTrue(acm.login("[email protected]", "12345678"));

acm.toggleActive("[email protected]");
//Test for disabled account
Assertions.assertFalse(acm.login("[email protected]", "12345678"));


}
}
48 changes: 47 additions & 1 deletion src/test/java/com/booleanuk/core/TodoItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}