// Copyright 2019 The Bazel Authors. All rights reserved.
//
// 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.devtools.build.lib.analysis.config;

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

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.config.transitions.NoTransition;
import com.google.devtools.build.lib.analysis.config.transitions.NullTransition;
import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition;
import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for {@link TransitionFactories}. */
@RunWith(JUnit4.class)
public class TransitionFactoriesTest {

  @Test
  public void noTransition() {
    TransitionFactory<TransitionFactory.Data> factory =
        TransitionFactories.of(NoTransition.INSTANCE);
    assertThat(factory).isNotNull();
    assertThat(NoTransition.isInstance(factory)).isTrue();
    assertThat(factory.isSplit()).isFalse();
  }

  @Test
  public void nullTransition() {
    TransitionFactory<TransitionFactory.Data> factory =
        TransitionFactories.of(NullTransition.INSTANCE);
    assertThat(factory).isNotNull();
    assertThat(NullTransition.isInstance(factory)).isTrue();
    assertThat(factory.isSplit()).isFalse();
  }

  @Test
  public void splitTransition() {
    TransitionFactory<TransitionFactory.Data> factory =
        TransitionFactories.of(
            (SplitTransition)
                (buildOptions, eventHandler) ->
                    ImmutableMap.of("test0", buildOptions.clone().underlying()));
    assertThat(factory).isNotNull();
    assertThat(factory.isSplit()).isTrue();
  }
}
