Skip to content

Emma Lövgren #45

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

public class Account {
private String email;
private String password;
private boolean status;

public Account(String email, String password) throws Exception {
this.setEmail(email);
this.setPassword(password);
this.status = false;
}

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

// TODO:
// Should return false if following domain model idea
// Or throw an error instead of just printing out to the console.
// System.out.println("ERROR: Email is not valid.");
this.email = null;
throw new Exception("ERROR: Email is not valid.");
}

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

public void setStatus(boolean status) {
this.status = status;
}
}
20 changes: 14 additions & 6 deletions src/main/java/com/booleanuk/core/TodoItem.java
Original file line number Diff line number Diff line change
@@ -1,21 +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 TodoItem(String title, String detail, String status) {
public TodoItem(String title, String detail) {
this.title = title;
this.detail = detail;
this.status = status;
this.status = "incomplete";
}

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

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

public void markAsComplete() {
this.setStatus("complete");
}

public void markAsIncomplete() {
this.setStatus("incomplete");
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/booleanuk/core/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| Classes | Variables | Methods | Scenario | Output |
|------------------------------------------|------------|----------------------------------|---------------------------------------|----------------------|
| `Account(String email, String password)` | `email` | `- setEmail(String email)` | Valid email. | true |
| | | | Invalid email. | false, error message |
| | `password` | `- setPassword(String password)` | Valid password. | true |
| | | | Invalid password. | false, error message |
| | `status` | `- setStatus(boolean status)` | Change status to enabled or disabled. | - |
| | | `+ enable()` | Set status to enabled. | - |
| | | `+ disable()` | Set status to enabled. | - |
| | | `+ login()` | Account is enabled. | true |
| | | | Account is enabled. | false |
15 changes: 15 additions & 0 deletions src/test/java/com/booleanuk/core/AccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.booleanuk.core;

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

public class AccountTest {

@Test
public void checkValidEmail() throws Exception {
Account account = new Account("email", "password");

// Assertions.assertThrows(Exeption(), "ERROR: Email is not valid.");

}
}
10 changes: 10 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,14 @@

class TodoItemTest {

@Test
public void checkSetStatus() {
TodoItem todo = new TodoItem("Todo", "JUnit testing");

todo.markAsComplete();
Assertions.assertEquals("complete", todo.getStatus());

todo.markAsIncomplete();
Assertions.assertEquals("incomplete", todo.getStatus());
}
}
Loading