/*
 * Copyright 2017-present Facebook, Inc.
 *
 * 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.facebook.buck.js;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.facebook.buck.model.FlavorDomainException;
import com.facebook.buck.model.Flavored;
import com.facebook.buck.model.InternalFlavor;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class JsFlavorValidationCommonTest {

  @Parameterized.Parameter public Flavored description;

  @Parameterized.Parameters(name = "{0}")
  public static Collection<Flavored> getDescriptions() {
    return Arrays.asList(new JsLibraryDescription(), new JsBundleDescription());
  }

  @Test
  public void testEmptyFlavors() {
    assertTrue(description.hasFlavors(ImmutableSet.of()));
  }

  @Test
  public void testReleaseFlavor() {
    assertTrue(description.hasFlavors(ImmutableSet.of(JsFlavors.RELEASE)));
  }

  @Test
  public void testAndroidFlavor() {
    assertTrue(description.hasFlavors(ImmutableSet.of(JsFlavors.ANDROID)));
    assertTrue(description.hasFlavors(ImmutableSet.of(JsFlavors.ANDROID, JsFlavors.RELEASE)));
  }

  @Test
  public void testIosFlavor() {
    assertTrue(description.hasFlavors(ImmutableSet.of(JsFlavors.IOS)));
    assertTrue(description.hasFlavors(ImmutableSet.of(JsFlavors.IOS, JsFlavors.RELEASE)));
  }

  @Test(expected = FlavorDomainException.class)
  public void testMultiplePlatforms() {
    description.hasFlavors(ImmutableSet.of(JsFlavors.ANDROID, JsFlavors.IOS));
  }

  @Test
  public void testUnknownFlavors() {
    assertFalse(description.hasFlavors(ImmutableSet.of(InternalFlavor.of("unknown"))));
    assertFalse(
        description.hasFlavors(ImmutableSet.of(InternalFlavor.of("unknown"), JsFlavors.RELEASE)));
  }
}

@@ -903,19 +903,19 @@
 mmutable
-Set
+Map
 ;%0Aimport
@@ -919,24 +919,46 @@
 ort 
-java.util.Arrays
+com.google.common.collect.ImmutableSet
 ;%0Aim
@@ -980,24 +980,46 @@
 Collection;%0A
+import java.util.Map;%0A
 import org.j
@@ -1184,48 +1184,586 @@
 %0A%0A  
-@Parameterized.Parameter public Flavored
+// Keeping separate map of class to instance objects only to have good names in test name%0A  // because @Parameterized.Parameters(name = %22%7B0%7D%22) will call toString() which by default resolves%0A  // to unstable string and cause test tracking system to explode test names%0A  // NOTE: JUnit does not support callbacks to infer name from%0A  static final Map%3CClass%3C?%3E, Flavored%3E TEST_DATA =%0A      ImmutableMap.of(%0A          JsLibraryDescription.class, new JsLibraryDescription(),%0A          JsBundleDescription.class, new JsBundleDescription());%0A%0A  @Parameterized.Parameter public Class%3C?%3E
  des
@@ -1842,24 +1842,24 @@
 lection%3C
-Flavored
+Class%3C?%3E
 %3E getDes
@@ -1887,63 +1887,98 @@
 urn 
-Arrays.asList(new JsLibraryDescription(), new JsBundleD
+TEST_DATA.keySet();%0A  %7D%0A%0A  private Flavored getTestInstance() %7B%0A    return TEST_DATA.get(d
 escr
@@ -1983,18 +1983,16 @@
 cription
-()
 );%0A  %7D%0A%0A
@@ -2045,35 +2045,41 @@
  assertTrue(
-description
+getTestInstance()
 .hasFlavors(
@@ -2159,35 +2159,41 @@
  assertTrue(
-description
+getTestInstance()
 .hasFlavors(
@@ -2290,35 +2290,41 @@
  assertTrue(
-description
+getTestInstance()
 .hasFlavors(
@@ -2372,35 +2372,41 @@
  assertTrue(
-description
+getTestInstance()
 .hasFlavors(
@@ -2518,35 +2518,41 @@
  assertTrue(
-description
+getTestInstance()
 .hasFlavors(
@@ -2600,27 +2600,33 @@
 ertTrue(
-description
+getTestInstance()
 .hasFlav
@@ -2775,35 +2775,41 @@
 rms() %7B%0A    
-description
+getTestInstance()
 .hasFlavors(
@@ -2926,27 +2926,33 @@
 rtFalse(
-description
+getTestInstance()
 .hasFlav
@@ -3029,27 +3029,46 @@
         
-description
+getTestInstance()%0A            
 .hasFlav

Fix test names exploding in TestPilot