forked from modelcontextprotocol/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptReferenceEqualsTest.java
More file actions
87 lines (65 loc) · 3.45 KB
/
PromptReferenceEqualsTest.java
File metadata and controls
87 lines (65 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 2025 - 2025 the original author or authors.
*/
package io.modelcontextprotocol.spec;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test class to verify the equals method implementation for PromptReference.
*/
class PromptReferenceEqualsTest {
@Test
void testEqualsWithSameIdentifierAndType() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
McpSchema.PromptReference ref2 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Different Title");
assertTrue(ref1.equals(ref2), "PromptReferences with same identifier and type should be equal");
assertEquals(ref1.hashCode(), ref2.hashCode(), "Equal objects should have same hash code");
}
@Test
void testEqualsWithDifferentIdentifier() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt-1", "Test Title");
McpSchema.PromptReference ref2 = new McpSchema.PromptReference("ref/prompt", "test-prompt-2", "Test Title");
assertFalse(ref1.equals(ref2), "PromptReferences with different identifiers should not be equal");
}
@Test
void testEqualsWithDifferentType() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
McpSchema.PromptReference ref2 = new McpSchema.PromptReference("ref/other", "test-prompt", "Test Title");
assertFalse(ref1.equals(ref2), "PromptReferences with different types should not be equal");
}
@Test
void testEqualsWithNull() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
assertFalse(ref1.equals(null), "PromptReference should not be equal to null");
}
@Test
void testEqualsWithDifferentClass() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
String other = "not a PromptReference";
assertFalse(ref1.equals(other), "PromptReference should not be equal to different class");
}
@Test
void testEqualsWithSameInstance() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
assertTrue(ref1.equals(ref1), "PromptReference should be equal to itself");
}
@Test
void testEqualsIgnoresTitle() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Title 1");
McpSchema.PromptReference ref2 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Title 2");
McpSchema.PromptReference ref3 = new McpSchema.PromptReference("ref/prompt", "test-prompt", null);
assertTrue(ref1.equals(ref2), "PromptReferences should be equal regardless of title");
assertTrue(ref1.equals(ref3), "PromptReferences should be equal even when one has null title");
assertTrue(ref2.equals(ref3), "PromptReferences should be equal even when one has null title");
}
@Test
void testHashCodeConsistency() {
McpSchema.PromptReference ref1 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Test Title");
McpSchema.PromptReference ref2 = new McpSchema.PromptReference("ref/prompt", "test-prompt", "Different Title");
assertEquals(ref1.hashCode(), ref2.hashCode(), "Objects that are equal should have the same hash code");
// Call hashCode multiple times to ensure consistency
int hashCode1 = ref1.hashCode();
int hashCode2 = ref1.hashCode();
assertEquals(hashCode1, hashCode2, "Hash code should be consistent across multiple calls");
}
}