Add Note model object
This commit is contained in:
21
src/main/java/model/Note.java
Normal file
21
src/main/java/model/Note.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public record Note(int id, String message, String from, String to, long timestamp, int fame) {
|
||||||
|
private static final int PLACEHOLDER_ID = -1;
|
||||||
|
|
||||||
|
public Note {
|
||||||
|
Objects.requireNonNull(message);
|
||||||
|
Objects.requireNonNull(from);
|
||||||
|
Objects.requireNonNull(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Note createNormal(String message, String from, String to, long timestamp) {
|
||||||
|
return new Note(PLACEHOLDER_ID, message, from, to, timestamp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Note createGift(String message, String from, String to, long timestamp) {
|
||||||
|
return new Note(PLACEHOLDER_ID, message, from, to, timestamp, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/test/java/model/NoteTest.java
Normal file
28
src/test/java/model/NoteTest.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class NoteTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void requireNonNullMessage() {
|
||||||
|
assertThrows(NullPointerException.class, () -> new Note(1, null, "from", "to", System.currentTimeMillis(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void requireNonNullFrom() {
|
||||||
|
assertThrows(NullPointerException.class, () -> new Note(2, "message", null, "to", System.currentTimeMillis(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void requireNonNullTo() {
|
||||||
|
assertThrows(NullPointerException.class, () -> new Note(3, "message", "from", null, System.currentTimeMillis(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNew() {
|
||||||
|
assertDoesNotThrow(() -> new Note(4, "message", "from", "to", System.currentTimeMillis(), 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user