-
Notifications
You must be signed in to change notification settings - Fork 28
Add 5 unit tests for untested domain classes #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Check warning on line 10 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
|
|
||
| @Test | ||
| public void testDefaultConstructor() { | ||
|
Check warning on line 13 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
| TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent(); | ||
| assertNotNull(event); | ||
| assertNull(event.getId()); | ||
| assertNull(event.getArtifact()); | ||
| assertNull(event.getMetadata()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllArgsConstructor() { | ||
|
Check warning on line 22 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
| Artifact artifact = new Artifact(); | ||
| artifact.setName("test-artifact"); | ||
| artifact.setDescription("A test artifact"); | ||
|
|
||
| Map<String, Object> 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() { | ||
|
Check warning on line 41 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
| TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent(); | ||
|
|
||
| Artifact artifact = new Artifact(); | ||
| artifact.setName("updated-artifact"); | ||
|
|
||
| Map<String, Object> 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() { | ||
|
Check warning on line 60 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
| Artifact artifact = new Artifact(); | ||
| artifact.setName("simple-artifact"); | ||
|
|
||
| TaskArtifactUpdateEvent event = new TaskArtifactUpdateEvent("task-789", artifact); | ||
| assertNotNull(event); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEqualsAndHashCode() { | ||
|
Check warning on line 69 in src/test/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEventTest.java
|
||
| Artifact artifact = new Artifact(); | ||
| artifact.setName("artifact-1"); | ||
|
|
||
| Map<String, Object> 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()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Check warning on line 7 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
|
|
||
| @Test | ||
| public void testDefaultConstructor() { | ||
|
Check warning on line 10 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
| TaskCancelParams params = new TaskCancelParams(); | ||
| assertNotNull(params); | ||
| assertNull(params.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetId() { | ||
|
Check warning on line 17 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
| TaskCancelParams params = new TaskCancelParams(); | ||
| params.setId("task-to-cancel-123"); | ||
|
|
||
| assertEquals("task-to-cancel-123", params.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToString() { | ||
|
Check warning on line 25 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
| TaskCancelParams params = new TaskCancelParams(); | ||
| params.setId("cancel-456"); | ||
|
|
||
| String toString = params.toString(); | ||
| assertNotNull(toString); | ||
| assertTrue(toString.contains("cancel-456")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEqualsAndHashCode() { | ||
|
Check warning on line 35 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
| 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() { | ||
|
Check warning on line 51 in src/test/java/io/github/vishalmysore/a2a/domain/TaskCancelParamsTest.java
|
||
| TaskCancelParams params = new TaskCancelParams(); | ||
| params.setId("initial-id"); | ||
| assertEquals("initial-id", params.getId()); | ||
|
|
||
| params.setId(null); | ||
| assertNull(params.getId()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Check warning on line 7 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
|
|
||
| @Test | ||
| public void testDefaultConstructor() { | ||
|
Check warning on line 10 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); | ||
| assertNotNull(params); | ||
| assertNull(params.getTaskId()); | ||
| assertNull(params.getNotificationUrl()); | ||
| assertNull(params.getPushNotificationUrl()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetTaskId() { | ||
|
Check warning on line 19 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); | ||
| params.setTaskId("task-789"); | ||
|
|
||
| assertEquals("task-789", params.getTaskId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetNotificationUrl() { | ||
|
Check warning on line 27 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); | ||
| params.setNotificationUrl("https://example.com/notify"); | ||
|
|
||
| assertEquals("https://example.com/notify", params.getNotificationUrl()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetPushNotificationUrl() { | ||
|
Check warning on line 35 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| TaskSetPushNotificationParams params = new TaskSetPushNotificationParams(); | ||
| params.setPushNotificationUrl("https://example.com/push"); | ||
|
|
||
| assertEquals("https://example.com/push", params.getPushNotificationUrl()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllFieldsSet() { | ||
|
Check warning on line 43 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| 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() { | ||
|
Check warning on line 55 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| 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() { | ||
|
Check warning on line 71 in src/test/java/io/github/vishalmysore/a2a/domain/TaskSetPushNotificationParamsTest.java
|
||
| 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")); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Check warning on line 10 in src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java
|
||
|
|
||
| @Test | ||
| public void testConstructorWithMessage() { | ||
|
Check warning on line 13 in src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java
|
||
| 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() { | ||
|
Check warning on line 22 in src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java
|
||
| Map<String, Object> 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() { | ||
|
Check warning on line 37 in src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java
|
||
| VersionNotSupportedError error = new VersionNotSupportedError("test"); | ||
| assertTrue(error instanceof JSONRPCError); | ||
| } | ||
|
|
||
| @Test | ||
| public void testErrorCodeIsAlwaysNeg32009() { | ||
|
Check warning on line 43 in src/test/java/io/github/vishalmysore/a2a/domain/VersionNotSupportedErrorTest.java
|
||
| VersionNotSupportedError error1 = new VersionNotSupportedError("msg1"); | ||
| VersionNotSupportedError error2 = new VersionNotSupportedError("msg2", new HashMap<>()); | ||
|
|
||
| assertEquals(-32009, error1.getCode()); | ||
| assertEquals(-32009, error2.getCode()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Check warning on line 10 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
|
|
||
| @Test | ||
| public void testDefaultValues() { | ||
|
Check warning on line 13 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCRequest request = new JSONRPCRequest(); | ||
| assertEquals("2.0", request.getJsonrpc()); | ||
| assertNull(request.getId()); | ||
| assertNull(request.getMethod()); | ||
| assertNull(request.getParams()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetId() { | ||
|
Check warning on line 22 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCRequest request = new JSONRPCRequest(); | ||
| request.setId("req-001"); | ||
| assertEquals("req-001", request.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetMethod() { | ||
|
Check warning on line 29 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCRequest request = new JSONRPCRequest(); | ||
| request.setMethod("tools/list"); | ||
| assertEquals("tools/list", request.getMethod()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetAndGetParams() { | ||
|
Check warning on line 36 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| 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() { | ||
|
Check warning on line 52 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCRequest request = new JSONRPCRequest(); | ||
| assertEquals("2.0", request.getJsonrpc()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFullRequest() { | ||
|
Check warning on line 58 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| 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() { | ||
|
Check warning on line 76 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCBatchRequest batch = new JSONRPCBatchRequest(); | ||
| List<Object> 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() { | ||
|
Check warning on line 97 in src/test/java/io/github/vishalmysore/mcp/domain/JSONRPCRequestTest.java
|
||
| JSONRPCBatchResponse batch = new JSONRPCBatchResponse(); | ||
| List<Object> 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()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Test masks broken two-arg constructor that sends null fields in production SSE events
The
testTwoArgConstructortest only assertsassertNotNull(event)on the result ofnew TaskArtifactUpdateEvent("task-789", artifact), but the underlying constructor atsrc/main/java/io/github/vishalmysore/a2a/domain/TaskArtifactUpdateEvent.java:18-19has an empty body — it never assignsthis.id = taskIdorthis.artifact = artifact. This meansevent.getId()andevent.getArtifact()are bothnullafter construction.This constructor is used in production at
src/main/java/io/github/vishalmysore/a2a/server/DyanamicTaskContoller.java:531to emit SSE artifact update events:new TaskArtifactUpdateEvent(id, artifact). Because the constructor body is empty, all such events are sent with nullidand nullartifactfields. The test provides false confidence by not verifying the fields are actually set.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.