File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
main/java/com/github/codeboyzhou/mcp/declarative/util
test/java/com/github/codeboyzhou/mcp/declarative/util Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,6 @@ public static boolean isBlank(String str) {
4646 * @return the original string if it is not blank, otherwise the default value
4747 */
4848 public static String defaultIfBlank (String str , String defaultValue ) {
49- return str == null || str . isBlank () ? defaultValue : str ;
49+ return isBlank (str ) ? defaultValue : str ;
5050 }
5151}
Original file line number Diff line number Diff line change @@ -34,9 +34,25 @@ void testToJsonString_shouldSucceed() {
3434
3535 @ Test
3636 void testToJsonString_shouldThrowException () {
37- CircularReference circularRef = new CircularReference ();
3837 assertThrows (
39- McpServerJsonProcessingException .class , () -> JacksonHelper .toJsonString (circularRef ));
38+ McpServerJsonProcessingException .class ,
39+ () -> JacksonHelper .toJsonString (new CircularReference ()));
40+ }
41+
42+ @ Test
43+ void testFromJson_shouldSucceed () {
44+ String json = "{\" name\" :\" test\" ,\" age\" :25}" ;
45+ Person person = JacksonHelper .fromJson (json , Person .class );
46+ assertEquals ("test" , person .name );
47+ assertEquals (25 , person .age );
48+ }
49+
50+ @ Test
51+ void testFromJson_shouldThrowException () {
52+ String json = "{\" name\" :\" test\" ,\" age\" :25}" ;
53+ assertThrows (
54+ McpServerJsonProcessingException .class ,
55+ () -> JacksonHelper .fromJson (json , CircularReference .class ));
4056 }
4157
4258 @ Test
Original file line number Diff line number Diff line change @@ -11,6 +11,17 @@ void testConstructor_shouldThrowException() {
1111 assertThrows (UnsupportedOperationException .class , StringHelper ::new );
1212 }
1313
14+ @ Test
15+ void testIsBlank_shouldReturnTrueWhenStrIsBlank () {
16+ assertTrue (StringHelper .isBlank (StringHelper .EMPTY ));
17+ assertTrue (StringHelper .isBlank (StringHelper .SPACE ));
18+ }
19+
20+ @ Test
21+ void testIsBlank_shouldReturnFalseWhenStrIsNotBlank () {
22+ assertFalse (StringHelper .isBlank ("test" ));
23+ }
24+
1425 @ Test
1526 void testDefaultIfBlank_shouldReturnDefaultValueWhenStrIsNull () {
1627 assertEquals ("default" , StringHelper .defaultIfBlank (null , "default" ));
You can’t perform that action at this time.
0 commit comments