/*
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

class YamlStringToSpecTreeConverterTest {
  @Test
  void testThrowFileNotFoundException() {
    assertThrows(
        FileNotFoundException.class,
        () ->
            YamlStringToSpecTreeConverter.convertYamlFileToSpecTree(
                "src/test/resources/fakepath.yaml"));
  }

  @Test
  void testConvertYamlFileToMap() throws FileNotFoundException {
    Map<String, Object> expected = new LinkedHashMap<>();

    Map<String, Object> license = new LinkedHashMap<>();
    license.put("name", "MIT");

    Map<String, Object> info = new LinkedHashMap<>();
    info.put("license", license);
    info.put("title", "Swagger Petstore");

    expected.put("openapi", "3.0.0");
    expected.put("info", info);

    assertThat(
            YamlStringToSpecTreeConverter.convertYamlFileToSpecTree(
                "src/test/resources/simplepetstore3.yaml"))
        .isEqualTo(expected);
  }

  @Test
  void testConvertEmptyStringToEmptyMap() {
    Map<String, Object> expected = new LinkedHashMap<>();

    assertThat(YamlStringToSpecTreeConverter.convertYamlStringToSpecTree("")).isEqualTo(expected);
  }

  @Test
  void testConvertOrderFileToYaml() throws FileNotFoundException {
    Map<String, Object> expected = new LinkedHashMap<>();

    Map<String, Object> license = new LinkedHashMap<>();
    license.put("name", "MIT");

    Map<String, Object> paths = new LinkedHashMap<>();
    Map<String, Object> pets = new LinkedHashMap<>();

    pets.put("get", null);
    paths.put("/pets", pets);

    expected.put("paths", paths);
    expected.put("openapi", null);
    expected.put("info", null);

    assertThat(
            YamlStringToSpecTreeConverter.convertYamlFileToSpecTree(
                "src/test/resources/order.yaml"))
        .isEqualTo(expected);
  }
}

@@ -855,38 +855,53 @@
 oid 
-testThrowFileNotFoundException
+convertYamlFileToSpecTree_withFakePath_throws
 () %7B
@@ -1109,29 +1109,25 @@
 Test%0A  void 
-testC
+c
 onvertYamlFi
@@ -1130,19 +1130,51 @@
 mlFileTo
-Map
+SpecTree_withValidYamlFile_succeeds
 () throw
@@ -1750,730 +1750,144 @@
 oid 
-testC
+c
 onvert
-EmptyStringToEmptyMap() %7B%0A    Map%3CString, Object%3E expected = new LinkedHashMap%3C%3E();%0A%0A    assertThat(YamlStringToSpecTreeConverter.convertYamlStringToSpecTree(%22%22)).isEqualTo(expected);%0A  %7D%0A%0A  @Test%0A  void testConvertOrderFileToYaml() throws FileNotFoundException %7B%0A    Map%3CString, Object%3E expected = new LinkedHashMap%3C%3E();%0A%0A    Map%3CString, Object%3E license = new LinkedHashMap%3C%3E();%0A    license.put(%22name%22, %22MIT%22);%0A%0A    Map%3CString, Object%3E paths = new LinkedHashMap%3C%3E();%0A    Map%3CString, Object%3E pets = new LinkedHashMap%3C%3E();%0A%0A    pets.put(%22get%22, null);%0A    paths.put(%22/pets%22, pets);%0A%0A    expected.put(%22paths%22, paths);%0A    expected.put(%22openapi%22, null);%0A    expected.put(%22info%22, null);%0A%0A    assertThat(%0A            
+YamlFileToSpecTree_withEmptyString_returnsEmptyMap() %7B%0A    Map%3CString, Object%3E expected = new LinkedHashMap%3C%3E();%0A%0A    assertThat(
 Yaml
@@ -1915,36 +1915,38 @@
 rter.convertYaml
-File
+String
 ToSpecTree(%0A    
@@ -1944,67 +1944,12 @@
 ree(
-%0A                %22src/test/resources/order.yaml%22))%0A        
+%22%22))
 .isE

update test with new naming convention