package com.github.therapi.apidoc;

import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static org.junit.Assert.assertFalse;

import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

public class JsonSchemaProviderTest {

    private static class Zoo {
        public String name;
        public List<Animal> animals;
    }

    private static class Animal {
        public String species;
    }

    private static class NoPublicFields {
        private int x;
    }

    @Test
    public void testGetSchema() throws Exception {
        Optional<String> schema = new JsonSchemaProvider().getSchema(new ObjectMapper(), Zoo.class);
        String expected = "{\n" +
                "  \"type\" : \"object\",\n" +
                "  \"id\" : \"urn:jsonschema:com:github:therapi:apidoc:JsonSchemaProviderTest:Zoo\",\n" +
                "  \"properties\" : {\n" +
                "    \"name\" : {\n" +
                "      \"type\" : \"string\"\n" +
                "    },\n" +
                "    \"animals\" : {\n" +
                "      \"type\" : \"array\",\n" +
                "      \"items\" : {\n" +
                "        \"type\" : \"object\",\n" +
                "        \"$ref\" : \"urn:jsonschema:com:github:therapi:apidoc:JsonSchemaProviderTest:Animal\"\n" +
                "      }\n" +
                "    }\n" +
                "  }\n" +
                "}";
        assertJsonEquals(expected, schema.get());
    }

    @Test
    public void noSchema() throws Exception {
        assertFalse(new JsonSchemaProvider().getSchema(new ObjectMapper(), NoPublicFields.class).isPresent());
    }
}
@@ -319,28 +319,25 @@
 private 
-static class
+interface
  Zoo %7B%0A 
@@ -347,26 +347,24 @@
     
-public 
 String 
-n
+getN
 ame
+()
 ;%0A  
@@ -369,23 +369,16 @@
         
-public 
 List%3CAni
@@ -382,23 +382,28 @@
 Animal%3E 
-a
+getA
 nimals
+()
 ;%0A    %7D%0A
@@ -415,28 +415,25 @@
 private 
-static class
+interface
  Animal 
@@ -446,29 +446,27 @@
     
-public 
 String 
-s
+getS
 pecies
+()
 ;%0A  

fix findbugs issues