aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Ortlepp <post@ortlepp.eu>2024-05-07 00:07:36 +0200
committerThorsten Ortlepp <post@ortlepp.eu>2024-05-07 00:07:36 +0200
commitb0a3a919b7f6f82cf2afa780132dfefeddf78418 (patch)
treebd3c112a3772ad5b34679fa08257e53b9fa23325
parentfdf19cdf6446815ed155bfb70564e5af8bdedd74 (diff)
downloadnotification-sender-b0a3a919b7f6f82cf2afa780132dfefeddf78418.zip
omit empty notifications
-rw-r--r--src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java6
-rw-r--r--src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java2
-rw-r--r--src/test/java/eu/ortlepp/notificationsender/NotificationHandlerTest.java2
3 files changed, 6 insertions, 4 deletions
diff --git a/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java b/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java
index 17b4a46..6a93992 100644
--- a/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java
+++ b/src/main/java/eu/ortlepp/notificationsender/NotificationHandler.java
@@ -78,7 +78,7 @@ public class NotificationHandler implements RequestHandler<Map<String, Object>,
/**
- * Extract the notifications from the input JSON.
+ * Extract the notifications from the input JSON. Omit empty notifications.
*
* @param body The input JSON
* @return The extracted messages; empty list if an error occurred while parsing the JSON
@@ -87,7 +87,9 @@ public class NotificationHandler implements RequestHandler<Map<String, Object>,
try {
Notifications notifications =
new ObjectMapper().readValue(body.toString(), Notifications.class);
- return Arrays.asList(notifications.messages());
+ var messages = new ArrayList<>(Arrays.asList(notifications.messages()));
+ messages.removeIf(message -> message.trim().isEmpty());
+ return messages;
} catch (JsonProcessingException ex) {
logger.log("parsing input JSON failed : " + ex.getMessage());
return new ArrayList<>();
diff --git a/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java b/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java
index 8c39c72..94d4462 100644
--- a/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java
+++ b/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java
@@ -17,7 +17,7 @@ public interface NotificationSender {
/**
- * Format notifications for sending.
+ * Format notifications for sending (default implementation).
* If only one notification is passed, it is returned as is.
* If multiple notifications are passed, a numbered list of notifications is returned.
*
diff --git a/src/test/java/eu/ortlepp/notificationsender/NotificationHandlerTest.java b/src/test/java/eu/ortlepp/notificationsender/NotificationHandlerTest.java
index 9777356..e5b2bfb 100644
--- a/src/test/java/eu/ortlepp/notificationsender/NotificationHandlerTest.java
+++ b/src/test/java/eu/ortlepp/notificationsender/NotificationHandlerTest.java
@@ -17,7 +17,7 @@ import org.junit.jupiter.api.Test;
public class NotificationHandlerTest {
- private static final Object INPUT_VALID = "{\"messages\":[\"first\",\"second\"]}";
+ private static final Object INPUT_VALID = "{\"messages\":[\"first\",\"\",\"second\"]}";
private static final Object INPUT_INVALID = "{\"messages\":\"some text\"}";
private final Context context = new FakeContext();