Skip to content

Commit

Permalink
add a test case for an enum implementing JSONString
Browse files Browse the repository at this point in the history
  • Loading branch information
Simulant87 committed Feb 25, 2024
1 parent 77c899d commit d17bbbd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/java/org/json/junit/JSONStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,22 @@ public void testNullStringValue() throws Exception {
}
}

@Test
public void testEnumJSONString() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", MyEnum.MY_ENUM);
assertEquals("{\"key\":\"myJsonString\"}", jsonObject.toString());
}

private enum MyEnum implements JSONString {
MY_ENUM;

@Override
public String toJSONString() {
return "\"myJsonString\"";
}
}

/**
* A JSONString that returns a valid JSON string value.
*/
Expand Down

0 comments on commit d17bbbd

Please sign in to comment.