/*
 * Copyright (C) 2024 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.android.tools.test;

import java.util.Set;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runners.model.RunnerBuilder;

public class ModuleRunnerBuilder extends RunnerBuilder {
  private final RunnerBuilder delegate;

  private static final Set<String> INNER_RUNNERS = Set.of(
    "com.android.tools.test.InnerRunner", // For tests
    "org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners"
  );

  public ModuleRunnerBuilder(RunnerBuilder delegate) {
    this.delegate = delegate;
  }

  @Override
  public Runner runnerForClass(Class<?> aClass) throws Throwable {
    RunWith annotation = aClass.getAnnotation(RunWith.class);
    if (annotation != null) {
      Class<? extends Runner> value = annotation.value();
      if (INNER_RUNNERS.contains(value.getCanonicalName())) {
        return new JUnit3RunnerWithInnersForBazel(aClass);
      }
    }
    return new ExpectedFailureRunner(delegate.runnerForClass(aClass));
  }
}
