add a test case for an enum implementing JSONString

(cherry picked from commit d17bbbd4174b3d84f70a6f0fdce9edc10d846a1a)
This commit is contained in:
Simulant 2024-02-25 09:45:57 +01:00
parent 0c5cf18255
commit 60090a7167

View File

@ -319,6 +319,22 @@ public class JSONStringTest {
}
}
@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.
*/