Add Note model object

This commit is contained in:
P0nk
2022-12-26 14:54:35 +01:00
parent 2d7d113458
commit 188eb74a70
2 changed files with 49 additions and 0 deletions

View 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);
}
}

View 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));
}
}