Skip to content

Commit

Permalink
Added exeption handling for Message class
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Strand Prestmo authored and Robin Strand Prestmo committed Feb 20, 2026
1 parent 9cd4106 commit 9b82784
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,51 @@
import java.time.LocalDateTime;
import java.util.UUID;

// Unntakshåndtering mangler
// Enhetstester mangler

/**
* Represents a message
*
* @Author Robin Strand Prestmo
* @author Robin Strand Prestmo
*/
public class Message {
private UUID id;
private String title;
private String from;
private String content;
private LocalDateTime timeAndDate;
private final UUID id;
private final String title;
private final String from;
private final String content;
private final LocalDateTime timeAndDate;

/**
* Creates a message with an unique identifier.
* The message includes a title, a string who its from,
* Creates a message with a unique identifier.
* The message includes a title, a string who it's from,
* content and the time and date.
*
* @param id an unique identifier using UUID
* @param title the title of the message
* @param from who the message is from
* @param content the content of the message
* @param timeAndDate when the message was sent.
* @throws IllegalArgumentException if title, from or content is null or blank.
*/
public Message(UUID id,
String title,
public Message(String title,
String from,
String content,
LocalDateTime timeAndDate) {
this.id = id;
String content) {

if (title == null || title.isBlank()) {
throw new IllegalArgumentException("Title cannot be null or blank.");
}

if (from == null || from.isBlank()) {
throw new IllegalArgumentException("From cannot be null or blank.");
}

if (content == null || content.isBlank()) {
throw new IllegalArgumentException("Content cannot be null or blank.");
}

this.id = UUID.randomUUID();
this.title = title;
this.from = from;
this.content = content;
this.timeAndDate = timeAndDate;
this.timeAndDate = LocalDateTime.now();
}

public UUID getId() {
Expand Down

0 comments on commit 9b82784

Please sign in to comment.