Skip to content

Commit

Permalink
Merge branch 'master' into 'ui-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
jepunnerud committed Nov 16, 2022
2 parents b8ace9c + 4d694b4 commit 0d69a53
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 215 deletions.
13 changes: 13 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<tfoot>.*</tfoot>'
artifacts:
paths:
- $CI_BUILDS_DIR/$CI_PROJECT_PATH/script/report/target/site/jacoco-aggregate/*
retry: 2
22 changes: 15 additions & 7 deletions script/core/main/src/main/java/core/main/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public String getBoardDescription() {
}

public List<Note> getNotes() {
return notes;
return new ArrayList<Note>(notes);
}

public List<Checklist> getChecklists() {
return checklists;
return new ArrayList<Checklist>(checklists);
}

public void setBoardName(String boardName) {
Expand All @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion script/core/main/src/main/java/core/main/BoardElement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package core.main;

public class BoardElement {
public abstract class BoardElement {

private String title;
private boolean isPinned = false;
Expand Down
25 changes: 20 additions & 5 deletions script/core/main/src/main/java/core/main/Checklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChecklistLine> getChecklistLines() {
orderLines();
return new ArrayList<ChecklistLine>(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<ChecklistLine> 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() {
Expand Down
6 changes: 3 additions & 3 deletions script/core/main/src/main/java/core/main/ChecklistLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
9 changes: 3 additions & 6 deletions script/core/main/src/main/java/core/main/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Board> boards = new ArrayList<>();

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand Down Expand Up @@ -64,11 +61,11 @@ public String getLastName() {
}

public List<Board> getBoards() {
return boards;
return new ArrayList<Board>(boards);
}

public void setBoards(List<Board> boards) {
this.boards = boards;
this.boards = new ArrayList<Board>(boards);
}

}
213 changes: 116 additions & 97 deletions script/core/main/src/test/java/core/main/BoardTest.java
Original file line number Diff line number Diff line change
@@ -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<Note> 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<Note> 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<Checklist> 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());
});
}
}
Loading

0 comments on commit 0d69a53

Please sign in to comment.