@Test public void generateCreatesSchemaFromExampleJSONAsStringInput() throws IOException { String jsonContent = IOUtils.toString(this.getClass().getResourceAsStream("/example-json/user.json")); ObjectNode schemaNode = JsonNodeFactory.instance.objectNode(); final SchemaRule mockSchemaRule = mock(SchemaRule.class); final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class); when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON); final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class); when(mockSchemaGenerator.schemaFromExample(new ObjectMapper().readTree(jsonContent))).thenReturn(schemaNode); final RuleFactory mockRuleFactory = mock(RuleFactory.class); when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule); when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig); new SchemaMapper(mockRuleFactory, mockSchemaGenerator).generate(new JCodeModel(), "User", "com.example.package", jsonContent); ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class); verify(mockSchemaRule).apply(eq("User"), eq(schemaNode), eq(null), capturePackage.capture(), Mockito.isA(Schema.class)); assertThat(capturePackage.getValue().name(), is("com.example.package")); }
public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) { JPackage jpackage = codeModel._package(packageName); ObjectNode schemaNode = readSchema(schemaUrl); return ruleFactory.getSchemaRule().apply(className, schemaNode, null, jpackage, new Schema(null, schemaNode, null)); }
SchemaMapper { public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) { JPackage jpackage = codeModel._package(packageName); ObjectNode schemaNode = readSchema(schemaUrl); return ruleFactory.getSchemaRule().apply(className, schemaNode, null, jpackage, new Schema(null, schemaNode, null)); } }
SchemaMapper { public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) { JPackage jpackage = codeModel._package(packageName); ObjectNode schemaNode = readSchema(schemaUrl); return ruleFactory.getSchemaRule().apply(className, schemaNode, null, jpackage, new Schema(null, schemaNode, null)); } SchemaMapper(RuleFactory ruleFactory, SchemaGenerator schemaGenerator);  SchemaMapper(); }
SchemaMapper { public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) { JPackage jpackage = codeModel._package(packageName); ObjectNode schemaNode = readSchema(schemaUrl); return ruleFactory.getSchemaRule().apply(className, schemaNode, null, jpackage, new Schema(null, schemaNode, null)); } SchemaMapper(RuleFactory ruleFactory, SchemaGenerator schemaGenerator);  SchemaMapper(); JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl); JType generate(JCodeModel codeModel, String className, String packageName, String json,
            URI schemaLocation); JType generate(JCodeModel codeModel, String className, String packageName, String json); }
SchemaMapper { public JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl) { JPackage jpackage = codeModel._package(packageName); ObjectNode schemaNode = readSchema(schemaUrl); return ruleFactory.getSchemaRule().apply(className, schemaNode, null, jpackage, new Schema(null, schemaNode, null)); } SchemaMapper(RuleFactory ruleFactory, SchemaGenerator schemaGenerator);  SchemaMapper(); JType generate(JCodeModel codeModel, String className, String packageName, URL schemaUrl); JType generate(JCodeModel codeModel, String className, String packageName, String json,
            URI schemaLocation); JType generate(JCodeModel codeModel, String className, String packageName, String json);  }