Skip to content
Closed
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
41 changes: 33 additions & 8 deletions src/main/java/com/booleanuk/core/TodoItem.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
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) {
setTitle(title);
setDetail(detail);
setStatus(status);
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
if (title == null) {
throw new IllegalArgumentException("Null not allowed for attribute title");
}
this.title = title;
this.detail = detail;
this.status = status;
}

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

public void setDetail(String detail) {
if (detail == null) {
throw new IllegalArgumentException("Null not allowed for attribute detail");
}
this.detail = detail;
}

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

public void setStatus(String status) {
if (status == null) {
throw new IllegalArgumentException("Null not allowed for attribute status");
}
this.status = status;
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/booleanuk/core/UserEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.booleanuk.core;

public class UserEntity {
private String email;
private String password;
private boolean enabled;

private UserEntity() {

}

private UserEntity(String email, String password) {
setEmail(email);
setPassword(password);
setEnabled(false);
}

public static UserEntity createAccount(String email, String password) {
return new UserEntity(email, password);
}

public boolean checkAbleToLogin() {
return isEnabled();
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
if (email == null) {
throw new IllegalArgumentException("Email cannot be null");
}
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
if (password.length() < 8) {
throw new IllegalArgumentException("Password must be at least eight characters long");
}
this.password = password;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
24 changes: 24 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,28 @@

class TodoItemTest {

@Test
public void setTitleNullNotAllowed() {
TodoItem ti = new TodoItem("title", "detail", "status");

Assertions.assertThrows(IllegalArgumentException.class, () -> ti.setTitle(null));

}

@Test
public void setDetailNullNotAllowed() {
TodoItem ti = new TodoItem("title", "detail", "status");

Assertions.assertThrows(IllegalArgumentException.class, () -> ti.setDetail(null));

}

@Test
public void setStatusNullNotAllowed() {
TodoItem ti = new TodoItem("title", "detail", "status");

Assertions.assertThrows(IllegalArgumentException.class, () -> ti.setDetail(null));

}

}
38 changes: 38 additions & 0 deletions src/test/java/com/booleanuk/core/UserEntityTest.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;

public class UserEntityTest {

@Test
public void createAccountInvalidEmail() {
Assertions.assertThrows(IllegalArgumentException.class, () -> UserEntity.createAccount(null, "12345678"));
}

@Test
public void createAccountInvalidPassword() {
Assertions.assertThrows(IllegalArgumentException.class, () -> UserEntity.createAccount("email", "1234567"));
}

@Test
public void createAccountValidCredentials() {
Assertions.assertInstanceOf(UserEntity.class, UserEntity.createAccount("email", "12345678"));
}

@Test
public void checkLoginDisabledAccountReturnsFalse() {
UserEntity u = UserEntity.createAccount("email", "12345678");

Assertions.assertFalse(u.checkAbleToLogin());
}

@Test
public void checkLoginEnabledAccountReturnsTrue() {
UserEntity u = UserEntity.createAccount("email", "12345678");

u.setEnabled(true);

Assertions.assertTrue(u.checkAbleToLogin());
}
}
Loading