package com.github.kongchen.swagger.docgen.mavenplugin;

import com.google.common.collect.Sets;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.models.Info;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ApiSourceTest {

    @Spy
    protected ApiSource apiSource;

    @BeforeMethod
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testGetInfo0VendorExtensions() {
        Map<String, Object> expectedExtensions = new HashMap<String, Object>();
        expectedExtensions.put("x-logo", new HashMap<String, Object>(){{
            put("logo", "logo url");
            put("description", "This is our logo.");
        }});
        expectedExtensions.put("x-website", new HashMap<String, Object>(){{
            put("website", "website url");
            put("description", "This is our website.");
        }});


        Set<Class<?>> validClasses = Sets.newHashSet(ApiSourceTestClass.class);

        Mockito.when(apiSource.getValidClasses(SwaggerDefinition.class)).thenReturn(validClasses);
        Info info = apiSource.getInfo();

        Map<String, Object> vendorExtensions = info.getVendorExtensions();
        Assert.assertEquals(vendorExtensions.size(), 2);
        Assert.assertEquals(vendorExtensions, expectedExtensions);
    }

    @SwaggerDefinition(info = @io.swagger.annotations.Info(
            title = "ApiSourceTestClass",
            version = "1.0.0",
            extensions = {
                    @Extension(name = "logo", properties = {
                            @ExtensionProperty(name = "logo", value = "logo url"),
                            @ExtensionProperty(name = "description", value = "This is our logo.")
                    }),
                    @Extension(name = "website", properties = {
                            @ExtensionProperty(name = "website", value = "website url"),
                            @ExtensionProperty(name = "description", value = "This is our website.")
                    })
            }
    ))
    private static class ApiSourceTestClass {

    }
}

@@ -785,34 +785,20 @@
 Object%3E 
-expectedExtensions
+logo
  = new H
@@ -835,85 +835,13 @@
     
-expectedExtensions.put(%22x-logo%22, new HashMap%3CString, Object%3E()%7B%7B%0A            
+logo.
 put(
@@ -861,36 +861,37 @@
  url%22);%0A        
-    
+logo.
 put(%22description
@@ -919,64 +919,46 @@
 %22);%0A
-        %7D%7D);%0A        expectedExtensions.put(%22x-
+%0A        Map%3CString, Object%3E 
 website
-%22,
+ =
  new
@@ -987,10 +987,9 @@
 t%3E()
-%7B%7B
+;
 %0A   
@@ -989,28 +989,32 @@
 ();%0A        
-    
+website.
 put(%22website
@@ -1040,20 +1040,24 @@
         
-    
+website.
 put(%22des
@@ -1092,24 +1092,25 @@
 ite.%22);%0A
+%0A
         
 %7D%7D);%0A%0A%0A 
@@ -1105,10 +1105,179 @@
     
-%7D%7D
+Map%3CString, Object%3E expectedExtensions = new HashMap%3CString, Object%3E();%0A        expectedExtensions.put(%22x-logo%22, logo);%0A        expectedExtensions.put(%22x-website%22, website
 );%0A%0A

Make codeacy happy "Non-static initializers are confusing"