Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.object.ClassToSchemaTest.verifyTypeAndFormatOfFieldInProperties
Source:ClassToSchemaTest.java
...27 private void verifyTypeOfFieldInProperties(JsonObject obj, String expected, String fieldName){28 assertEquals(expected, obj.get("properties").getAsJsonObject()29 .get(fieldName).getAsJsonObject().get("type").getAsString());30 }31 private void verifyTypeAndFormatOfFieldInProperties(JsonObject obj, String type, String format, String fieldName){32 JsonObject field = obj.get("properties").getAsJsonObject().get(fieldName).getAsJsonObject();33 assertEquals(type, field.get("type").getAsString());34 assertEquals(format, field.get("format").getAsString());35 }36 @Test37 public void testNumeric(){38 String schema = ClassToSchema.getOrDeriveSchema(DtoNumeric.class);39 JsonObject json = parse(schema);40 JsonObject obj = json.get(DtoNumeric.class.getName()).getAsJsonObject();41 assertNotNull(obj);42 assertNotNull(obj.get("type"));43 assertNotNull(obj.get("properties"));44 assertEquals(2, obj.entrySet().size());45 assertEquals("object", obj.get("type").getAsString());46 assertEquals(12, obj.get("properties").getAsJsonObject().entrySet().size());47 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int8", "byte_p");48 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int8", "byte_w");49 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int16", "short_p");50 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int16", "short_w");51 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int32", "integer_p");52 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int32", "integer_w");53 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int64", "long_p");54 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int64", "long_w");55 verifyTypeAndFormatOfFieldInProperties(obj, "number", "float", "float_p");56 verifyTypeAndFormatOfFieldInProperties(obj, "number", "float", "float_w");57 verifyTypeAndFormatOfFieldInProperties(obj, "number", "double", "double_p");58 verifyTypeAndFormatOfFieldInProperties(obj, "number", "double", "double_w");59 }60 private void verifyTypeInArray(JsonObject obj, String expected, String fieldName){61 JsonObject array = obj.get("properties").getAsJsonObject()62 .get(fieldName).getAsJsonObject();63 assertEquals("array", array.get("type").getAsString());64 assertEquals(expected, array.get("items").getAsJsonObject().get("type").getAsString());65 }66 @Test67 public void testExtending(){68 String schema = ClassToSchema.getOrDeriveSchema(DtoExtending.class);69 JsonObject json = parse(schema);70 JsonObject obj = json.get(DtoExtending.class.getName()).getAsJsonObject();71 // WARN: this is limitation in GSON, as it does not have entryList(), so we72 // cannot verify that entries are unique, and not repeated by mistake :(...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!