Skip to content

Commit e401e9e

Browse files
codeboyzhoutzolov
authored andcommitted
feat(tests): Add unit tests for Assert and Utils classes (#70)
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent 55ee156 commit e401e9e

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*/
4+
5+
package io.modelcontextprotocol.util;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.util.List;
10+
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
class AssertTests {
14+
15+
@Test
16+
void testCollectionNotEmpty() {
17+
IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class,
18+
() -> Assert.notEmpty(null, "collection is null"));
19+
assertEquals("collection is null", e1.getMessage());
20+
21+
IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class,
22+
() -> Assert.notEmpty(List.of(), "collection is empty"));
23+
assertEquals("collection is empty", e2.getMessage());
24+
25+
assertDoesNotThrow(() -> Assert.notEmpty(List.of("test"), "collection is not empty"));
26+
}
27+
28+
@Test
29+
void testObjectNotNull() {
30+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
31+
() -> Assert.notNull(null, "object is null"));
32+
assertEquals("object is null", e.getMessage());
33+
34+
assertDoesNotThrow(() -> Assert.notNull("test", "object is not null"));
35+
}
36+
37+
@Test
38+
void testStringHasText() {
39+
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
40+
() -> Assert.hasText(null, "string is null"));
41+
assertEquals("string is null", e.getMessage());
42+
43+
assertDoesNotThrow(() -> Assert.hasText("test", "string is not empty"));
44+
}
45+
46+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*/
4+
5+
package io.modelcontextprotocol.util;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.util.Collection;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
import static org.junit.jupiter.api.Assertions.assertFalse;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
class UtilsTests {
17+
18+
@Test
19+
void testHasText() {
20+
assertFalse(Utils.hasText(null));
21+
assertFalse(Utils.hasText(""));
22+
assertFalse(Utils.hasText(" "));
23+
assertTrue(Utils.hasText("test"));
24+
}
25+
26+
@Test
27+
void testCollectionIsEmpty() {
28+
assertTrue(Utils.isEmpty((Collection<?>) null));
29+
assertTrue(Utils.isEmpty(List.of()));
30+
assertFalse(Utils.isEmpty(List.of("test")));
31+
}
32+
33+
@Test
34+
void testMapIsEmpty() {
35+
assertTrue(Utils.isEmpty((Map<?, ?>) null));
36+
assertTrue(Utils.isEmpty(Map.of()));
37+
assertFalse(Utils.isEmpty(Map.of("key", "value")));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)