Skip to content

Commit

Permalink
add test for enum validation in okhttp-gson models
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Nov 7, 2023
1 parent 083ddc7 commit e875cf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
sha256: db505f7801fef62c13a08a8e9ca1fc4c5c947ab46b46f12943139d353feacf17
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
sha256: 3371236d615e7fb79ed87d00c9fc486c31c379195a658781ac9440f0e3228d62
sha256: 6db714e9744c150c8982c3cb18e4f37a9c1ecd8f72f6d58943986e781ab4a344
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
sha256: 0d64cdc11809a7b5b952ccdad2bd91bd0045b3894d6fabf3e368fa0be12b8217
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,15 @@ public void testAdditionalProperties() throws Exception {
z.putAdditionalProperty("new_object", t);
assertEquals(z.toJson(), "{\"type\":\"plains\",\"className\":\"zebra\",\"new_key\":\"new_value\",\"new_boolean\":true,\"new_object\":{\"id\":34,\"name\":\"just a tag\"},\"from_json\":4567,\"from_json_map\":{\"nested_string\":\"nested_value\"},\"new_number\":1.23}");
}


@Test
public void testInvalidEnumValueException() {
// test Pet with invalid status
String str = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"],\"status\":\"sleeping\"}";
Exception exception = assertThrows(java.lang.IllegalArgumentException.class, () -> {
Pet t7 = Pet.fromJson(str);
});
assertTrue(exception.getMessage().contains("Unexpected value 'sleeping'"));
}
}

0 comments on commit e875cf6

Please sign in to comment.