### Question:
SchemaProcessor { public void processSchema(Schema schema) { if (schema == null) { return; } if (schema.get$ref() != null) { processReferenceSchema(schema); } else { processSchemaType(schema); } } SchemaProcessor(ResolverCache cache, OpenAPI openAPI); void processSchema(Schema schema); void processSchemaType(Schema schema); void processPropertySchema(Schema schema); void processComposedSchema(ComposedSchema composedSchema); void processArraySchema(ArraySchema arraySchema);  }### Answer:
@Test public void testProcessRefSchema_ExternalRef() throws Exception { final String ref = "http: final String newRef = "bar"; setupPropertyAndExternalRefProcessors(); new StrictExpectations() {{ externalRefProcessor.processRefToExternalSchema(ref, RefFormat.URL); times = 1; result = newRef; }}; Schema refSchema = new Schema().$ref(ref); new SchemaProcessor(cache, openAPI).processSchema(refSchema); assertEquals(refSchema.get$ref(), "#/components/schemas/bar"); }
@Test public void testProcessRefSchema_InternalRef() throws Exception { final String ref = "#/components/schemas/bar"; setupPropertyAndExternalRefProcessors(); Schema refModel = new Schema().$ref(ref); new SchemaProcessor(cache, openAPI).processSchema(refModel); assertEquals(refModel.get$ref(), ref); }
@Test public void testProcessSchema() throws Exception { Schema property1 = new Schema(); Schema property2 = new Schema(); SchemaProcessor propertyProcessor = new SchemaProcessor(cache,openAPI); Schema model = new Schema(); model.addProperties("foo", property1); model.addProperties("bar", property2); propertyProcessor.processSchema(property1); propertyProcessor.processSchema(property2); new SchemaProcessor(cache, openAPI).processSchema(model); assertEquals(model.getProperties().get("foo"), property1); assertEquals(model.getProperties().get("bar"), property2); }
@Test public void testProcessRefProperty_ExternalRef() throws Exception { expectCreationOfExternalRefProcessor(); final String ref = "http: final Schema refProperty = new Schema().$ref(ref); expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar"); new SchemaProcessor(cache, openAPI).processSchema(refProperty); new FullVerifications() {{ }}; assertEquals(refProperty.get$ref(), "#/components/schemas/bar"); }
@Test public void testProcessRefProperty_InternalRef() throws Exception { expectCreationOfExternalRefProcessor(); final String expectedRef = "#/components/schemas/foo"; final Schema property = new Schema().$ref(expectedRef); new SchemaProcessor(cache, openAPI).processSchema(property); new FullVerifications() {{ }}; assertEquals(property.get$ref(), expectedRef); }
@Test public void testProcessArrayProperty_ItemsIsRefProperty() throws Exception { expectCreationOfExternalRefProcessor(); final String ref = "http: final Schema refProperty = new Schema().$ref(ref); ArraySchema arrayProperty = new ArraySchema(); arrayProperty.setItems(refProperty); expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar"); new SchemaProcessor(cache, openAPI).processSchema(arrayProperty); new FullVerifications() {{ }}; assertEquals((arrayProperty.getItems()).get$ref(), "#/components/schemas/bar"); }
@Test public void testProcessMapProperty_AdditionalPropertiesIsRefProperty() throws Exception { expectCreationOfExternalRefProcessor(); final String ref = "http: final Schema refProperty = new Schema().$ref(ref); refProperty.setAdditionalProperties(refProperty); expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar"); new SchemaProcessor(cache, openAPI).processSchema(refProperty); new FullVerifications() {{ }}; assertEquals((((Schema)refProperty.getAdditionalProperties()).get$ref()), "#/components/schemas/bar"); }