diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ea80432..ec241b8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,3 +28,16 @@ Checkstyle:
- cd script
- mvn checkstyle:check
retry: 2
+
+Jacoco:
+ image: maven:3-openjdk-16
+ stage: Java test
+ needs: []
+ script:
+ - cd script
+ - mvn jacoco:report-aggregate
+ - cat $CI_BUILDS_DIR/$CI_PROJECT_PATH/script/report/target/site/jacoco-aggregate/index.html | grep -o '
.*'
+ artifacts:
+ paths:
+ - $CI_BUILDS_DIR/$CI_PROJECT_PATH/script/report/target/site/jacoco-aggregate/*
+ retry: 2
diff --git a/script/core/main/src/main/java/core/main/Board.java b/script/core/main/src/main/java/core/main/Board.java
index 766bb7c..ec56f41 100644
--- a/script/core/main/src/main/java/core/main/Board.java
+++ b/script/core/main/src/main/java/core/main/Board.java
@@ -24,11 +24,11 @@ public String getBoardDescription() {
}
public List getNotes() {
- return notes;
+ return new ArrayList(notes);
}
public List getChecklists() {
- return checklists;
+ return new ArrayList(checklists);
}
public void setBoardName(String boardName) {
@@ -41,22 +41,30 @@ public void setBoardDescription(String description) {
}
public void addNote(Note note) {
- if (note == null && getNotes().size() + getChecklists().size() >= MAX_ELEMENTS) {
- throw new IllegalArgumentException();
+ if (note == null || getNotes().size() + getChecklists().size() >= MAX_ELEMENTS) {
+ throw new IllegalArgumentException("The number of notes exceed the maximum amount");
}
notes.add(note);
}
public void addChecklist(Checklist checklist) {
- if (checklist == null && getChecklists().size() + getNotes().size() >= MAX_ELEMENTS) {
- throw new IllegalArgumentException();
+ if (checklist == null || getChecklists().size() + getNotes().size() >= MAX_ELEMENTS) {
+ throw new IllegalArgumentException("The number of checklits exceed the maximum amount");
}
checklists.add(checklist);
}
+ public void clearCheckLists() {
+ checklists.clear();
+ }
+
+ public void clearNotes() {
+ notes.clear();
+ }
+
private void checkValidInputString(String input) {
if (input.isEmpty()) {
- throw new IllegalArgumentException("Innvalid argument");
+ throw new IllegalArgumentException("Invalid argument");
}
}
diff --git a/script/core/main/src/main/java/core/main/BoardElement.java b/script/core/main/src/main/java/core/main/BoardElement.java
index 1c33ba6..3de134a 100644
--- a/script/core/main/src/main/java/core/main/BoardElement.java
+++ b/script/core/main/src/main/java/core/main/BoardElement.java
@@ -1,6 +1,6 @@
package core.main;
-public class BoardElement {
+public abstract class BoardElement {
private String title;
private boolean isPinned = false;
diff --git a/script/core/main/src/main/java/core/main/Checklist.java b/script/core/main/src/main/java/core/main/Checklist.java
index 2dfb0b6..5e2d03a 100644
--- a/script/core/main/src/main/java/core/main/Checklist.java
+++ b/script/core/main/src/main/java/core/main/Checklist.java
@@ -13,17 +13,32 @@ public Checklist() {
setTitle("");
}
+ /**
+ * A getter than returns a copy of the checklistlines list. The use of copy is
+ * for security purposes.
+ *
+ * @return an array of checklines
+ *
+ */
+ public List getChecklistLines() {
+ orderLines();
+ return new ArrayList(checklistLines);
+ }
+
public void addChecklistLine() {
checklistLines.add(new ChecklistLine());
}
- public boolean isEmpty() {
- return (getTitle().isBlank() && checklistLines.isEmpty());
+ public void setChecklistline(int index, String line) {
+ checklistLines.get(index).setLine(line);
}
- public List getChecklistLines() {
- orderLines();
- return checklistLines;
+ public void setChecklistChecked(int index, Boolean checked) {
+ checklistLines.get(index).checked(checked);
+ }
+
+ public boolean isEmpty() {
+ return (getTitle().isBlank() && checklistLines.isEmpty());
}
public void orderLines() {
diff --git a/script/core/main/src/main/java/core/main/ChecklistLine.java b/script/core/main/src/main/java/core/main/ChecklistLine.java
index 3170177..a17e5aa 100644
--- a/script/core/main/src/main/java/core/main/ChecklistLine.java
+++ b/script/core/main/src/main/java/core/main/ChecklistLine.java
@@ -15,12 +15,12 @@ public Boolean getChecked() {
return checked;
}
- public void setLine(String line) {
+ protected void setLine(String line) {
this.line = line;
}
- public void checked(Boolean b) {
- checked = b;
+ protected void checked(Boolean checked) {
+ this.checked = checked;
}
}
diff --git a/script/core/main/src/main/java/core/main/User.java b/script/core/main/src/main/java/core/main/User.java
index 0375ddb..f2675a4 100644
--- a/script/core/main/src/main/java/core/main/User.java
+++ b/script/core/main/src/main/java/core/main/User.java
@@ -15,10 +15,7 @@ public class User {
private String username;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
- private String password;
- private String firstName;
- private String lastName;
-
+ private String password, firstName, lastName;
private List boards = new ArrayList<>();
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@@ -64,11 +61,11 @@ public String getLastName() {
}
public List getBoards() {
- return boards;
+ return new ArrayList(boards);
}
public void setBoards(List boards) {
- this.boards = boards;
+ this.boards = new ArrayList(boards);
}
}
diff --git a/script/core/main/src/test/java/core/main/BoardTest.java b/script/core/main/src/test/java/core/main/BoardTest.java
index 3495bab..545cfaf 100644
--- a/script/core/main/src/test/java/core/main/BoardTest.java
+++ b/script/core/main/src/test/java/core/main/BoardTest.java
@@ -1,97 +1,116 @@
-// package core.main;
-
-// import static org.junit.jupiter.api.Assertions.assertEquals;
-// import static org.junit.jupiter.api.Assertions.assertFalse;
-// import static org.junit.jupiter.api.Assertions.assertThrows;
-// import static org.junit.jupiter.api.Assertions.assertTrue;
-
-// import org.junit.jupiter.api.Test;
-
-// import java.util.Arrays;
-// import java.util.List;
-// import java.util.stream.IntStream;
-
-// public class BoardTest {
-
-// @Test
-// public void testConstructor() {
-// Board newBoard = new Board("Name", "Description");
-// assertEquals("Name", newBoard.getBoardName());
-// assertEquals("Description", newBoard.getBoardDescription());
-// }
-
-// @Test
-// public void testAddNote() {
-// // Tests that board is empty by default
-// Board board = new Board("Board", "Test");
-// assertTrue(board.getBoardElements().isEmpty());
-
-// // Tests that addBoardElement works as intended for a valid note
-// Note note = new Note("", "");
-// board.addBoardElement(note);
-// assertFalse(board.getBoardElements().isEmpty());
-// assertEquals(note, board.getBoardElements().get(0));
-
-// // Tests for exception case: note == null
-// assertThrows(IllegalArgumentException.class, () -> {
-// board.addBoardElement(null);
-// });
-
-// // Tests for exception case: Exceeded MAX_NOTES
-// // stream with 256
-// List notes = Arrays.asList(
-// IntStream.range(1, 256).mapToObj(i -> new Note(String.format("Note %d", i),
-// "")).toArray(Note[]::new));
-// notes.stream().forEach(n -> board.addBoardElement(n));
-// assertThrows(IllegalArgumentException.class, () -> {
-// board.addBoardElement(new Note("", ""));
-// });
-// }
-
-// @Test
-// public void testSetName() {
-// Board board = new Board("Name", "Description");
-// assertEquals("Name", board.getBoardName());
-// board.setBoardName("New Name");
-// assertEquals("New Name", board.getBoardName());
-// }
-
-// @Test
-// public void testSetDescription() {
-// Board board = new Board("Name", "Description");
-// assertEquals("Description", board.getBoardDescription());
-// board.setBoardDescription("New Description");
-// assertEquals("New Description", board.getBoardDescription());
-// }
-
-// @Test
-// public void testGetNote() {
-// Board board = new Board("Board", "Test");
-// Note note1 = new Note("Title1", "");
-// Note note2 = new Note("Title2", "");
-// board.addBoardElement(note1);
-// board.addBoardElement(note2);
-// assertEquals(note1, board.getBoardElement("Title1"));
-// assertEquals(note2, board.getBoardElement("Title2"));
-// }
-
-// @Test
-// public void testRemoveNote() {
-// Board board = new Board("Board", "Test");
-// Note note1 = new Note("Title1", "");
-// Note note2 = new Note("Title2", "");
-// board.addBoardElement(note1);
-// board.addBoardElement(note2);
-
-// // Tests that the board contains both notes
-// assertTrue(board.getBoardElements().contains(note1) &&
-// board.getBoardElements().contains(note2));
-
-// // Tests that removeNote() removed the intended note
-// board.removeNote("Title2");
-// assertFalse(board.getBoardElements().contains(note2));
-
-// // Tests that the other note is unaffected by removeNote()
-// assertTrue(board.getBoardElements().contains(note1));
-// }
-// }
+package core.main;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+
+public class BoardTest {
+
+ @Test
+ @DisplayName("Test constructor")
+ public void testConstructor() {
+ Board newBoard = new Board("Name", "Description");
+ assertEquals("Name", newBoard.getBoardName());
+ assertEquals("Description", newBoard.getBoardDescription());
+ }
+
+ @Test
+ @DisplayName("Test add note")
+ public void testAddNote() {
+ // Tests that board is empty by default
+ Board board = new Board("Board", "Test");
+ assertTrue(board.getNotes().isEmpty() && board.getChecklists().isEmpty());
+
+ // Tests that addBoardElement works as intended for a valid note
+ Note note = new Note();
+ board.addNote(note);
+ assertFalse(board.getNotes().isEmpty() && !board.getChecklists().isEmpty());
+ assertEquals(note, board.getNotes().get(0));
+
+ // Tests for exception case: note == null
+ assertThrows(IllegalArgumentException.class, () -> {
+ board.addNote(null);
+ });
+
+ // Tests for exception case: Exceeded MAX_NOTES
+ // stream with 256
+ List notes = Arrays.asList(
+ IntStream.range(1, 256).mapToObj(i -> new Note()).toArray(Note[]::new));
+ notes.stream().forEach(n -> board.addNote(n));
+ assertThrows(IllegalArgumentException.class, () -> {
+ board.addNote(new Note());
+ });
+ }
+
+ @Test
+ @DisplayName("Test set name")
+ public void testSetName() {
+ Board board = new Board("Name", "Description");
+ assertEquals("Name", board.getBoardName());
+ board.setBoardName("New Name");
+ assertEquals("New Name", board.getBoardName());
+ assertThrows(IllegalArgumentException.class, () -> {
+ board.setBoardName("");
+ });
+ assertThrows(NullPointerException.class, () -> {
+ board.setBoardName(null);
+ });
+ }
+
+ @Test
+ @DisplayName("Test set desctription")
+ public void testSetDescription() {
+ Board board = new Board("Name", "Description");
+ assertEquals("Description", board.getBoardDescription());
+ board.setBoardDescription("New Description");
+ assertEquals("New Description", board.getBoardDescription());
+ }
+
+ @Test
+ @DisplayName("Test get notes")
+ public void testGetNotes() {
+ Board board = new Board("Board", "Test");
+ Note note1 = new Note();
+ Note note2 = new Note();
+ board.addNote(note1);
+ board.addNote(note2);
+ assertEquals(note1, board.getNotes().get(0));
+ assertEquals(note2, board.getNotes().get(1));
+ }
+
+ @Test
+ @DisplayName("Test add checklists")
+ public void testAddChecklists() {
+ // Tests that board is empty by default
+ Board board = new Board("Board", "Test");
+ assertTrue(board.getChecklists().isEmpty() && board.getChecklists().isEmpty());
+
+ // Tests that addBoardElement works as intended for a valid Checklist
+ Checklist checklist = new Checklist();
+ board.addChecklist(checklist);
+ assertFalse(board.getChecklists().isEmpty() && !board.getChecklists().isEmpty());
+ assertEquals(checklist, board.getChecklists().get(0));
+
+ // Tests for exception case: Checklist == null
+ assertThrows(IllegalArgumentException.class, () -> {
+ board.addChecklist(null);
+ });
+
+ // Tests for exception case: Exceeded MAX_ChecklistS
+ // stream with 256
+ List checklists = Arrays.asList(
+ IntStream.range(1, 256).mapToObj(i -> new Checklist()).toArray(Checklist[]::new));
+ checklists.stream().forEach(n -> board.addChecklist(n));
+ assertThrows(IllegalArgumentException.class, () -> {
+ board.addChecklist(new Checklist());
+ });
+ }
+}
diff --git a/script/core/main/src/test/java/core/main/ChecklistTest.java b/script/core/main/src/test/java/core/main/ChecklistTest.java
new file mode 100644
index 0000000..960f2ff
--- /dev/null
+++ b/script/core/main/src/test/java/core/main/ChecklistTest.java
@@ -0,0 +1,37 @@
+package core.main;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+public class ChecklistTest {
+
+ @Test
+ @Disabled
+ @DisplayName("Test checklist")
+ public void testCecklist() {
+ Checklist checklist = new Checklist();
+ assertTrue(checklist.isEmpty());
+ checklist.addChecklistLine();
+ checklist.getChecklistLines().get(0).setLine("test");
+ assertFalse(checklist.isEmpty());
+ assertEquals("test", checklist.getChecklistLines().get(0).getLine());
+ checklist.addChecklistLine();
+ checklist.getChecklistLines().get(1).setLine("testing");
+ assertEquals(Arrays.asList("test", "testing"), Arrays.asList(checklist.getChecklistLines().get(0).getLine(),
+ checklist.getChecklistLines().get(1).getLine()));
+
+ assertFalse(checklist.getChecklistLines().get(0).getChecked());
+ checklist.getChecklistLines().get(0).checked(true);
+ assertTrue(checklist.getChecklistLines().get(0).getChecked());
+ Checklist checklist2 = new Checklist();
+ checklist2.setTitle("title");
+ assertFalse(checklist2.isEmpty());
+ }
+}
diff --git a/script/core/main/src/test/java/core/main/NoteTest.java b/script/core/main/src/test/java/core/main/NoteTest.java
index a42533f..e3d99d7 100644
--- a/script/core/main/src/test/java/core/main/NoteTest.java
+++ b/script/core/main/src/test/java/core/main/NoteTest.java
@@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
@@ -12,6 +13,7 @@
public class NoteTest {
@Test
+ @DisplayName("Test constructors")
public void testConstructors() {
Note emptyNote = new Note();
@@ -24,6 +26,7 @@ public void testConstructors() {
}
@Test
+ @DisplayName("Test set text")
public void testSetText() {
Note note = new Note();
@@ -37,6 +40,7 @@ public void testSetText() {
}
@Test
+ @DisplayName("Test set title")
public void testSetTitle() {
Note note = new Note();
@@ -50,6 +54,7 @@ public void testSetTitle() {
}
@Test
+ @DisplayName("Test set color")
public void testSetColor() {
Note note = new Note();
@@ -61,6 +66,7 @@ public void testSetColor() {
}
@Test
+ @DisplayName("Test get color values")
public void testGetColorValues() {
Note note = new Note();
@@ -79,6 +85,7 @@ public void testGetColorValues() {
}
@Test
+ @DisplayName("Test pin")
public void testPin() {
Note note = new Note();
diff --git a/script/core/main/src/test/java/core/main/UserTest.java b/script/core/main/src/test/java/core/main/UserTest.java
index c5aebb7..469742d 100644
--- a/script/core/main/src/test/java/core/main/UserTest.java
+++ b/script/core/main/src/test/java/core/main/UserTest.java
@@ -2,8 +2,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.stream.Collectors;
@@ -12,13 +14,34 @@
public class UserTest {
@Test
+ @DisplayName("Test constructor")
public void testConstructor() {
User user = new User("user", "password", "first", "last");
assertEquals("user", user.getUsername());
+ assertEquals("password", user.getPassword());
+ assertEquals("first", user.getFirstName());
+ assertEquals("last", user.getLastName());
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ new User("", "", "", "");
+ });
+ assertThrows(IllegalArgumentException.class, () -> {
+ new User(" ", " ", " ", " ");
+ });
+ assertThrows(IllegalArgumentException.class, () -> {
+ new User("\\\\/ ", "dnoijsd", "sdofh", "dailf");
+ });
+ assertThrows(IllegalArgumentException.class, () -> {
+ new User("null", "", "null", "null");
+ });
+ assertThrows(IllegalArgumentException.class, () -> {
+ new User("null", " ", "null", "null");
+ });
}
@Test
- public void testAddBoard() {
+ @DisplayName("Test set boards")
+ public void testSetBoards() {
User user = new User("user", "password", "first", "last");
user.setBoards(Stream.of(
new Board("board1", "desc1"),
@@ -27,23 +50,16 @@ public void testAddBoard() {
Board board3 = new Board("board3", "desc3");
assertEquals(user.getBoards().size(), 2);
assertFalse(user.getBoards().contains(board3));
- }
-
- @Test
- public void testRemoveBoard() {
- User user = new User("user", "password", "first", "last");
- user.setBoards(Stream.of(
- new Board("board1", "desc1"),
- new Board("board2", "desc2")).collect(Collectors.toList()));
- assertTrue(user.getBoards().size() == 2);
assertTrue(user.getBoards().get(0).getBoardName().equals("board1")
&& user.getBoards().get(1).getBoardName().equals("board2"));
+ }
- // Tests that the correct board is removed with removeBoard()
- // Board testBoard = user.getBoard("board2");
- // user.removeBoard("board2");
- // assertFalse(user.getBoards().contains(testBoard));
- // assertTrue(user.getBoards().size() == 1);
- // assertEquals("board1", user.getBoards().get(0).getBoardName());
+ @Test
+ @DisplayName("Test set password")
+ public void testSetPassword() {
+ User user = new User("test", "1", "test", "test");
+ assertEquals("1", user.getPassword());
+ user.setPassword("2");
+ assertEquals("2", user.getPassword());
}
}
diff --git a/script/ui/src/main/java/ui/BoardElementController.java b/script/ui/src/main/java/ui/BoardElementController.java
index 03185f8..a15fb86 100644
--- a/script/ui/src/main/java/ui/BoardElementController.java
+++ b/script/ui/src/main/java/ui/BoardElementController.java
@@ -20,7 +20,7 @@
public class BoardElementController {
- private static final int BOARD_ELEMENT_WIDTH = 200, BOARD_ELEMENT_HEIGHT = 230;
+ protected static final int BOARD_ELEMENT_WIDTH = 200, BOARD_ELEMENT_HEIGHT = 230;
private BoardElement boardElement;
@@ -97,12 +97,12 @@ private VBox generateChecklist() {
t.setDisable(
((Checklist) getBoardElement()).getChecklistLines().get(listElements.indexOf(t)).getChecked());
t.setOnKeyReleased((event) -> {
- ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText());
+ ((Checklist) boardElement).setChecklistline(listElements.indexOf(t), t.getText());
listener.updateCurrentBoardElements();
});
t.setOnKeyPressed(event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
- ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText());
+ ((Checklist) boardElement).setChecklistline(listElements.indexOf(t), t.getText());
((Checklist) boardElement).addChecklistLine();
listener.updateCurrentBoardElements();
listener.drawBoardElementControllers();
@@ -115,12 +115,12 @@ private VBox generateChecklist() {
listElements.add(t);
((Checklist) boardElement).addChecklistLine();
t.setOnKeyReleased((event) -> {
- ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText());
+ ((Checklist) boardElement).setChecklistline(listElements.indexOf(t), t.getText());
listener.updateCurrentBoardElements();
});
t.setOnKeyPressed(event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
- ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText());
+ ((Checklist) boardElement).setChecklistline(listElements.indexOf(t), t.getText());
((Checklist) boardElement).addChecklistLine();
listener.updateCurrentBoardElements();
listener.drawBoardElementControllers();
@@ -162,11 +162,9 @@ private VBox generateChecklist() {
checkBox.setSelected(checklist.getChecklistLines().get(listElements.indexOf(e)).getChecked());
checkBox.setOnAction(event -> {
if (checkBox.isSelected()) {
- checklist.getChecklistLines().get(listElements.indexOf(e)).checked(true);
- e.setDisable(true);
+ checklist.setChecklistChecked(listElements.indexOf(e), true);
} else {
- checklist.getChecklistLines().get(listElements.indexOf(e)).checked(false);
- e.setDisable(false);
+ checklist.setChecklistChecked(listElements.indexOf(e), false);
}
listener.updateCurrentBoardElements();
listener.drawBoardElementControllers();
@@ -215,7 +213,7 @@ public VBox generateControl() {
return null;
}
- public BoardElement getBoardElement() {
+ protected BoardElement getBoardElement() {
return boardElement;
}
}
diff --git a/script/ui/src/main/java/ui/LoginController.java b/script/ui/src/main/java/ui/LoginController.java
index ac40ee0..0490195 100644
--- a/script/ui/src/main/java/ui/LoginController.java
+++ b/script/ui/src/main/java/ui/LoginController.java
@@ -107,7 +107,12 @@ private void createWindowSizeListener() {
});
}
- public Button getLoginButton() {
+ protected Button getLoginButton() {
return loginButton;
}
+
+ protected Button getCreateNewUserButton() {
+ return createNewUserButton;
+ }
+
}
\ No newline at end of file
diff --git a/script/ui/src/main/java/ui/ScriptController.java b/script/ui/src/main/java/ui/ScriptController.java
index f69f52b..1006f26 100644
--- a/script/ui/src/main/java/ui/ScriptController.java
+++ b/script/ui/src/main/java/ui/ScriptController.java
@@ -34,9 +34,8 @@
public class ScriptController {
- private static final int BUTTON_WIDTH = 190, NOTE_SIZE = 200;
-
- private static final int H_GAP = 10;
+ protected static final int BUTTON_WIDTH = 190,
+ NOTE_SIZE = 200, H_GAP = 10;
private Board currentBoard = null;
@@ -144,8 +143,8 @@ private void editBoardDescription(KeyEvent event) throws IOException {
private void save() {
if (!(currentBoard == null)) {
- currentBoard.getChecklists().clear();
- currentBoard.getNotes().clear();
+ currentBoard.clearCheckLists();
+ currentBoard.clearNotes();
boardElementControllers.stream().map(c -> c.getBoardElement()).forEach(element -> {
if (element instanceof Note) {
Note note = (Note) element;
@@ -315,4 +314,8 @@ public void removeBoardElement(BoardElementController boardElementController) {
save();
}
+ protected Button getNewBoardButton() {
+ return newBoardButton;
+ }
+
}
\ No newline at end of file
diff --git a/script/ui/src/test/java/ui/LoginControllerTest.java b/script/ui/src/test/java/ui/LoginControllerTest.java
index 554b9bc..bd43f83 100644
--- a/script/ui/src/test/java/ui/LoginControllerTest.java
+++ b/script/ui/src/test/java/ui/LoginControllerTest.java
@@ -1,5 +1,6 @@
package ui;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -29,18 +30,21 @@ public void start(Stage stage) throws IOException {
@Test
@DisplayName("Test controller")
- void testController() {
+ public void testController() {
assertNotNull(controller);
}
@Test
@DisplayName("Test disabled when no username")
- void testEmpty() {
+ public void testLoginButtons() {
clickOn("#usernameField");
write("a");
+ assertTrue(controller.getLoginButton().isDisabled());
+ assertFalse(controller.getCreateNewUserButton().isDisabled());
press(KeyCode.BACK_SPACE);
release(KeyCode.BACK_SPACE);
assertTrue(controller.getLoginButton().isDisabled());
+ assertTrue(controller.getCreateNewUserButton().isDisabled());
}
}
diff --git a/script/ui/src/test/java/ui/ScriptControllerTest.java b/script/ui/src/test/java/ui/ScriptControllerTest.java
index 2d8faef..67e0015 100644
--- a/script/ui/src/test/java/ui/ScriptControllerTest.java
+++ b/script/ui/src/test/java/ui/ScriptControllerTest.java
@@ -1,70 +1,71 @@
-// package ui;
+package ui;
-// import static org.junit.jupiter.api.Assertions.assertEquals;
-// import static org.junit.jupiter.api.Assertions.assertFalse;
-// import static org.junit.jupiter.api.Assertions.assertNotNull;
-// import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-// import core.main.User;
-// import data.ScriptModule;
-// import javafx.fxml.FXMLLoader;
-// import javafx.scene.Parent;
-// import javafx.scene.Scene;
-// import javafx.stage.Stage;
-// import org.junit.jupiter.api.DisplayName;
-// import org.junit.jupiter.api.Test;
-// import org.testfx.framework.junit5.ApplicationTest;
+import core.main.User;
+import data.DataHandler;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.testfx.framework.junit5.ApplicationTest;
-// import java.io.IOException;
+import java.io.IOException;
-// public class ScriptControllerTest extends ApplicationTest {
+public class ScriptControllerTest extends ApplicationTest {
-// ScriptController controller;
-// ScriptModule dataHandler;
-// User user;
+ ScriptController controller;
+ DataHandler dataHandler;
+ User user;
-// @Override
-// public void start(Stage stage) throws IOException {
-// dataHandler = new ScriptModule();
-// user = new User("test_user");
-// dataHandler.removeUser("test_user");
-// dataHandler.write(user);
-// Globals.user = user;
-// Globals.windowHeight = 720;
-// Globals.windowWidth = 1280;
-// FXMLLoader loader = new
-// FXMLLoader(this.getClass().getResource("Script.fxml"));
-// Parent root = loader.load();
-// this.controller = loader.getController();
-// stage.setScene(new Scene(root));
-// stage.show();
-// }
+ @Override
+ public void start(Stage stage) throws IOException {
+ dataHandler = new DataHandler();
+ user = new User("username", "password", "first", "last");
+ dataHandler.removeUser("username");
+ dataHandler.write(user);
+ Globals.user = user;
+ Globals.windowHeight = 720;
+ Globals.windowWidth = 1280;
+ FXMLLoader loader = new FXMLLoader(this.getClass().getResource("Script.fxml"));
+ Parent root = loader.load();
+ this.controller = loader.getController();
+ stage.setScene(new Scene(root));
+ stage.show();
+ }
-// @Test
-// @DisplayName("Test controller")
-// void testController() {
-// assertNotNull(controller);
-// }
+ @Test
+ @DisplayName("Test controller")
+ void testController() {
+ assertNotNull(controller);
+ }
-// @Test
-// @DisplayName("Test create boards")
-// void testCreateBoards() {
-// assertTrue(controller.getBoards().size() == 0, "No boards should exist yet");
-// assertTrue(controller.getNewBoardButton().isDisabled(),
-// "New board button should be disabled when field is empty");
-// clickOn("#boardName");
-// write("test_board");
-// assertFalse(controller.getNewBoardButton().isDisabled(),
-// "New board button should be enabled when field has content");
-// clickOn("#newBoardButton");
-// assertTrue(controller.getBoards().size() == 1, "One board should exist");
-// clickOn("#test_board");
-// clickOn("#boardDescription");
-// write("test_description");
-// assertEquals(controller.getBoards().get(0).getBoardDescription(),
-// "test_description",
-// "Description field should be the same as board description");
-// assertTrue(controller.getBoards().get(0).getBoardElements().size() == 0,
-// "One note should exist in board");
-// }
-// }
+ @Test
+ @Disabled
+ @DisplayName("Test create boards")
+ void testCreateBoards() {
+ assertTrue(user.getBoards().size() == 0, "No boards should exist yet");
+ assertTrue(controller.getNewBoardButton().isDisabled(),
+ "New board button should be disabled when field is empty");
+ clickOn("#boardName");
+ write("test_board");
+ assertFalse(controller.getNewBoardButton().isDisabled(),
+ "New board button should be enabled when field has content");
+ clickOn("#newBoardButton");
+ assertTrue(user.getBoards().size() == 1, "One board should exist");
+ clickOn("#test_board");
+ clickOn("#boardDescription");
+ write("test_description");
+ assertEquals(user.getBoards().get(0).getBoardDescription(),
+ "test_description",
+ "Description field should be the same as board description");
+ assertTrue(user.getBoards().get(0).getNotes().size() == 0,
+ "One note should exist in board");
+ }
+}