From 34e6659db5fc65e0f123dd787b84f6d43bccb63f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 18:50:57 +0000 Subject: [PATCH] Add 5 unit tests for untested domain classes - TaskArtifactUpdateEventTest: tests constructors, getters/setters, equals/hashCode - TaskCancelParamsTest: tests id property, toString, equals/hashCode - TaskSetPushNotificationParamsTest: tests all fields, toString, equals/hashCode - VersionNotSupportedErrorTest: tests error code -32009, inheritance from JSONRPCError - JSONRPCRequestTest: tests JSONRPC request, params/meta, batch request/response Co-Authored-By: Vishal Mysore --- .../domain/TaskArtifactUpdateEventTest.java | 82 +++++++++++++ .../a2a/domain/TaskCancelParamsTest.java | 59 ++++++++++ .../TaskSetPushNotificationParamsTest.java | 81 +++++++++++++ .../domain/VersionNotSupportedErrorTest.java | 50 ++++++++ .../mcp/domain/JSONRPCRequestTest.java | 111 ++++++++++++++++++ 5 files changed, 383 insertions(+) create mode 100644 src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java create mode 100644 src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java create mode 100644 src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java create mode 100644 src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java create mode 100644 src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java diff --git a/src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java b/src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java new file mode 100644 index 0000000..68dffc9 --- /dev/null +++ b/src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java @@ -0,0 +1,82 @@ +package io.github.vishalmysore.a2a.domain; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +public class TaskArtifactUpdateEventTest { + + @Test + public void testDefaultConstructor() { + TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent(); + assertNotNull(event); + assertNull(event.getId()); + assertNull(event.getArtifact()); + assertNull(event.getMetadata()); + } + + @Test + public void testAllArgsConstructor() { + Artifact artifact = new Artifact(); + artifact.setName("test-artifact"); + artifact.setDescription("A test artifact"); + + Map metadata = new HashMap<>(); + metadata.put("key1", "value1"); + metadata.put("key2", 42); + + TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent("task-123", artifact, metadata); + + assertEquals("task-123", event.getId()); + assertEquals(artifact, event.getArtifact()); + assertEquals(metadata, event.getMetadata()); + assertEquals("value1", event.getMetadata().get("key1")); + assertEquals(42, event.getMetadata().get("key2")); + } + + @Test + public void testSettersAndGetters() { + TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent(); + + Artifact artifact = new Artifact(); + artifact.setName("updated-artifact"); + + Map metadata = new HashMap<>(); + metadata.put("status", "completed"); + + event.setId("event-456"); + event.setArtifact(artifact); + event.setMetadata(metadata); + + assertEquals("event-456", event.getId()); + assertEquals("updated-artifact", event.getArtifact().getName()); + assertEquals("completed", event.getMetadata().get("status")); + } + + @Test + public void testTwoArgConstructor() { + Artifact artifact = new Artifact(); + artifact.setName("simple-artifact"); + + TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent("task-789", artifact); + assertNotNull(event); + } + + @Test + public void testEqualsAndHashCode() { + Artifact artifact = new Artifact(); + artifact.setName("artifact-1"); + + Map metadata = new HashMap<>(); + metadata.put("key", "value"); + + TaskArtifactUpdateEvent event1 = new TaskArtifactUpdateEvent("id-1", artifact, metadata); + TaskArtifactUpdateEvent event2 = new TaskArtifactUpdateEvent("id-1", artifact, metadata); + + assertEquals(event1, event2); + assertEquals(event1.hashCode(), event2.hashCode()); + } +} diff --git a/src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java b/src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java new file mode 100644 index 0000000..f639ee6 --- /dev/null +++ b/src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java @@ -0,0 +1,59 @@ +package io.github.vishalmysore.a2a.domain; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class TaskCancelParamsTest { + + @Test + public void testDefaultConstructor() { + TaskCancelParams params = new TaskCancelParams(); + assertNotNull(params); + assertNull(params.getId()); + } + + @Test + public void testSetAndGetId() { + TaskCancelParams params = new TaskCancelParams(); + params.setId("task-to-cancel-123"); + + assertEquals("task-to-cancel-123", params.getId()); + } + + @Test + public void testToString() { + TaskCancelParams params = new TaskCancelParams(); + params.setId("cancel-456"); + + String toString = params.toString(); + assertNotNull(toString); + assertTrue(toString.contains("cancel-456")); + } + + @Test + public void testEqualsAndHashCode() { + TaskCancelParams params1 = new TaskCancelParams(); + params1.setId("same-id"); + + TaskCancelParams params2 = new TaskCancelParams(); + params2.setId("same-id"); + + TaskCancelParams params3 = new TaskCancelParams(); + params3.setId("different-id"); + + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + assertNotEquals(params1, params3); + } + + @Test + public void testSetIdToNull() { + TaskCancelParams params = new TaskCancelParams(); + params.setId("initial-id"); + assertEquals("initial-id", params.getId()); + + params.setId(null); + assertNull(params.getId()); + } +} diff --git a/src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java b/src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java new file mode 100644 index 0000000..e1d3172 --- /dev/null +++ b/src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java @@ -0,0 +1,81 @@ +package io.github.vishalmysore.a2a.domain; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class TaskSetPushNotificationParamsTest { + + @Test + public void testDefaultConstructor() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + assertNotNull(params); + assertNull(params.getTaskId()); + assertNull(params.getNotificationUrl()); + assertNull(params.getPushNotificationUrl()); + } + + @Test + public void testSetAndGetTaskId() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + params.setTaskId("task-789"); + + assertEquals("task-789", params.getTaskId()); + } + + @Test + public void testSetAndGetNotificationUrl() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + params.setNotificationUrl("https://example.com/notify"); + + assertEquals("https://example.com/notify", params.getNotificationUrl()); + } + + @Test + public void testSetAndGetPushNotificationUrl() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + params.setPushNotificationUrl("https://example.com/push"); + + assertEquals("https://example.com/push", params.getPushNotificationUrl()); + } + + @Test + public void testAllFieldsSet() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + params.setTaskId("task-100"); + params.setNotificationUrl("https://example.com/notify"); + params.setPushNotificationUrl("https://example.com/push"); + + assertEquals("task-100", params.getTaskId()); + assertEquals("https://example.com/notify", params.getNotificationUrl()); + assertEquals("https://example.com/push", params.getPushNotificationUrl()); + } + + @Test + public void testEqualsAndHashCode() { + TaskSetPushNotificationParams params1 = new TaskSetPushNotificationParams(); + params1.setTaskId("task-1"); + params1.setNotificationUrl("https://example.com/a"); + params1.setPushNotificationUrl("https://example.com/b"); + + TaskSetPushNotificationParams params2 = new TaskSetPushNotificationParams(); + params2.setTaskId("task-1"); + params2.setNotificationUrl("https://example.com/a"); + params2.setPushNotificationUrl("https://example.com/b"); + + assertEquals(params1, params2); + assertEquals(params1.hashCode(), params2.hashCode()); + } + + @Test + public void testToString() { + TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); + params.setTaskId("task-200"); + params.setNotificationUrl("https://example.com/notify"); + + String toString = params.toString(); + assertNotNull(toString); + assertTrue(toString.contains("task-200")); + assertTrue(toString.contains("https://example.com/notify")); + } +} diff --git a/src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java b/src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java new file mode 100644 index 0000000..f6cb7c6 --- /dev/null +++ b/src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java @@ -0,0 +1,50 @@ +package io.github.vishalmysore.a2a.domain; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +public class VersionNotSupportedErrorTest { + + @Test + public void testConstructorWithMessage() { + VersionNotSupportedError error = new VersionNotSupportedError("Version 0.5 is not supported"); + + assertEquals(-32009, error.getCode()); + assertEquals("Version 0.5 is not supported", error.getMessage()); + assertNull(error.getData()); + } + + @Test + public void testConstructorWithMessageAndData() { + Map data = new HashMap<>(); + data.put("requestedVersion", "0.5"); + data.put("supportedVersions", "1.0, 1.1"); + + VersionNotSupportedError error = new VersionNotSupportedError("Unsupported version", data); + + assertEquals(-32009, error.getCode()); + assertEquals("Unsupported version", error.getMessage()); + assertNotNull(error.getData()); + assertEquals("0.5", error.getData().get("requestedVersion")); + assertEquals("1.0, 1.1", error.getData().get("supportedVersions")); + } + + @Test + public void testInheritsFromJSONRPCError() { + VersionNotSupportedError error = new VersionNotSupportedError("test"); + assertTrue(error instanceof JSONRPCError); + } + + @Test + public void testErrorCodeIsAlwaysNeg32009() { + VersionNotSupportedError error1 = new VersionNotSupportedError("msg1"); + VersionNotSupportedError error2 = new VersionNotSupportedError("msg2", new HashMap<>()); + + assertEquals(-32009, error1.getCode()); + assertEquals(-32009, error2.getCode()); + } +} diff --git a/src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java b/src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java new file mode 100644 index 0000000..cee66ac --- /dev/null +++ b/src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java @@ -0,0 +1,111 @@ +package io.github.vishalmysore.mcp.domain; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class JSONRPCRequestTest { + + @Test + public void testDefaultValues() { + JSONRPCRequest request = new JSONRPCRequest(); + assertEquals("2.0", request.getJsonrpc()); + assertNull(request.getId()); + assertNull(request.getMethod()); + assertNull(request.getParams()); + } + + @Test + public void testSetAndGetId() { + JSONRPCRequest request = new JSONRPCRequest(); + request.setId("req-001"); + assertEquals("req-001", request.getId()); + } + + @Test + public void testSetAndGetMethod() { + JSONRPCRequest request = new JSONRPCRequest(); + request.setMethod("tools/list"); + assertEquals("tools/list", request.getMethod()); + } + + @Test + public void testSetAndGetParams() { + JSONRPCRequest request = new JSONRPCRequest(); + JSONRPCRequest.Params params = new JSONRPCRequest.Params(); + + JSONRPCRequest.Params.Meta meta = new JSONRPCRequest.Params.Meta(); + meta.setProgressToken("progress-token-123"); + params.setMeta(meta); + + request.setParams(params); + + assertNotNull(request.getParams()); + assertNotNull(request.getParams().getMeta()); + assertEquals("progress-token-123", request.getParams().getMeta().getProgressToken()); + } + + @Test + public void testJsonrpcVersionIsFixed() { + JSONRPCRequest request = new JSONRPCRequest(); + assertEquals("2.0", request.getJsonrpc()); + } + + @Test + public void testFullRequest() { + JSONRPCRequest request = new JSONRPCRequest(); + request.setId("42"); + request.setMethod("tools/call"); + + JSONRPCRequest.Params params = new JSONRPCRequest.Params(); + JSONRPCRequest.Params.Meta meta = new JSONRPCRequest.Params.Meta(); + meta.setProgressToken("token-abc"); + params.setMeta(meta); + request.setParams(params); + + assertEquals("42", request.getId()); + assertEquals("tools/call", request.getMethod()); + assertEquals("2.0", request.getJsonrpc()); + assertEquals("token-abc", request.getParams().getMeta().getProgressToken()); + } + + @Test + public void testBatchRequest() { + JSONRPCBatchRequest batch = new JSONRPCBatchRequest(); + List requests = new ArrayList<>(); + + JSONRPCRequest req1 = new JSONRPCRequest(); + req1.setId("1"); + req1.setMethod("tools/list"); + + JSONRPCRequest req2 = new JSONRPCRequest(); + req2.setId("2"); + req2.setMethod("tools/call"); + + requests.add(req1); + requests.add(req2); + batch.setJsonRpcRequests(requests); + + assertNotNull(batch.getJsonRpcRequests()); + assertEquals(2, batch.getJsonRpcRequests().size()); + } + + @Test + public void testBatchResponse() { + JSONRPCBatchResponse batch = new JSONRPCBatchResponse(); + List responses = new ArrayList<>(); + + JSONRPCResponse resp1 = new JSONRPCResponse(); + JSONRPCResponse resp2 = new JSONRPCResponse(); + + responses.add(resp1); + responses.add(resp2); + batch.setJsonRpcResponses(responses); + + assertNotNull(batch.getJsonRpcResponses()); + assertEquals(2, batch.getJsonRpcResponses().size()); + } +}