/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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
 *
 *      http://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.
 */

package com.google.gms.googleservices;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static com.google.common.truth.Truth.assertThat;

public class GoogleServicesPluginTest {

  @Test
  public void testNoFlavor() {
    List<String> output = toStringList(GoogleServicesTask.getJsonLocations("release"));
    assertThat(output).contains("src/release");
  }

  @Test
  public void testOneFlavor() {
    List<String> output =
        toStringList(GoogleServicesTask.getJsonLocations("flavor/release"));
    assertThat(output)
        .containsAllOf(
            "src/release",
            "src/flavorRelease",
            "src/flavor",
            "src/flavor/release",
            "src/release/flavor");
  }

  @Test
  public void testMultipleFlavors() {
    List<String> output =
        toStringList(GoogleServicesTask.getJsonLocations("flavorTest/release"));
    assertThat(output)
        .containsAllOf(
            "src/release",
            "src/flavorRelease",
            "src/flavor",
            "src/flavor/release",
            "src/release/flavorTest",
            "src/flavorTest",
            "src/flavorTestRelease",
            "src/flavor/test/release",
            "src/flavor/testRelease");
  }

  // This is necessary because some of the strings are actually groovy string implementations
  // which fail equality tests with java strings during testing
  private static List<String> toStringList(List<String> input) {
    ArrayList<String> strings = new ArrayList<>(input.size());
    for (Object oldString : input) {
      strings.add(oldString.toString());
    }
    return strings;
  }
}

@@ -995,24 +995,45 @@
 %22src/release
+/google-services.json
 %22);%0A  %7D%0A%0A  @
@@ -1235,32 +1235,53 @@
     %22src/release
+/google-services.json
 %22,%0A            %22
@@ -1289,32 +1289,53 @@
 rc/flavorRelease
+/google-services.json
 %22,%0A            %22
@@ -1336,32 +1336,53 @@
      %22src/flavor
+/google-services.json
 %22,%0A            %22
@@ -1391,32 +1391,53 @@
 c/flavor/release
+/google-services.json
 %22,%0A            %22
@@ -1454,16 +1454,37 @@
 e/flavor
+/google-services.json
 %22);%0A  %7D%0A
@@ -1700,32 +1700,53 @@
     %22src/release
+/google-services.json
 %22,%0A            %22
@@ -1758,24 +1758,45 @@
 lavorRelease
+/google-services.json
 %22,%0A         
@@ -1809,16 +1809,37 @@
 c/flavor
+/google-services.json
 %22,%0A     
@@ -1856,32 +1856,53 @@
 c/flavor/release
+/google-services.json
 %22,%0A            %22
@@ -1915,32 +1915,53 @@
 lease/flavorTest
+/google-services.json
 %22,%0A            %22
@@ -1974,16 +1974,37 @@
 avorTest
+/google-services.json
 %22,%0A     
@@ -2028,24 +2028,45 @@
 rTestRelease
+/google-services.json
 %22,%0A         
@@ -2092,16 +2092,37 @@
 /release
+/google-services.json
 %22,%0A     
@@ -2151,16 +2151,37 @@
 tRelease
+/google-services.json
 %22);%0A  %7D%0A

fix tests