Skip to content

Commit

Permalink
Description redacted.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=123431237
  • Loading branch information
Googler authored and dslomov committed May 30, 2016
1 parent 2ce814b commit 6f418ed
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ java_library(
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/model",
"//third_party:dagger",
"//third_party:guava",
"//third_party:guice",
"//third_party:joda_time",
"//third_party:jsr305",
"//third_party:junit4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,29 @@

package com.google.testing.junit.runner;

import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Uninterruptibles;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.testing.junit.runner.internal.StackTraces;
import com.google.testing.junit.runner.internal.Stderr;
import com.google.testing.junit.runner.internal.Stdout;
import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.Config;
import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.SuiteClass;
import com.google.testing.junit.runner.junit4.JUnit4Runner;
import com.google.testing.junit.runner.junit4.JUnit4RunnerModule;
import com.google.testing.junit.runner.model.AntXmlResultWriter;
import com.google.testing.junit.runner.model.XmlResultWriter;

import dagger.Component;
import dagger.Module;
import dagger.Provides;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.PrintStream;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

/**
* A class to run JUnit tests in a controlled environment.
*
Expand Down Expand Up @@ -143,19 +142,11 @@ private static int runTestsInSuite(String suiteClassName, String[] args) {
}
}

JUnit4Runner runner =
DaggerBazelTestRunner_JUnit4Bazel.builder()
.suiteClass(new SuiteClass(suite))
.config(new Config(args))
.build()
.runner();
return runner.run().wasSuccessful() ? 0 : 1;
}
Injector injector = Guice.createInjector(
new BazelTestRunnerModule(suite, ImmutableList.copyOf(args)));

@Singleton
@Component(modules = {BazelTestRunnerModule.class})
interface JUnit4Bazel {
JUnit4Runner runner();
JUnit4Runner runner = injector.getInstance(JUnit4Runner.class);
return runner.run().wasSuccessful() ? 0 : 1;
}

private static Class<?> getTestClass(String name) {
Expand Down Expand Up @@ -190,25 +181,29 @@ public void run() {
thread.start();
}

@Module(includes = JUnit4RunnerModule.class)
static class BazelTestRunnerModule {
@Provides
static XmlResultWriter resultWriter(AntXmlResultWriter impl) {
return impl;
static class BazelTestRunnerModule extends AbstractModule {
final Class<?> suite;
final List<String> args;

BazelTestRunnerModule(Class<?> suite, List<String> args) {
this.suite = suite;
this.args = args;
}

@Override
protected void configure() {
install(JUnit4RunnerModule.create(suite, args));
bind(XmlResultWriter.class).to(AntXmlResultWriter.class);
}

@Provides
@Singleton
@Stdout
static PrintStream stdoutStream() {
@Provides @Singleton @Stdout
PrintStream provideStdoutStream() {
return System.out;
}

@Provides
@Singleton
@Stderr
static PrintStream stderrStream() {
@Provides @Singleton @Stderr
PrintStream provideStderrStream() {
return System.err;
}
}
};
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ java_library(
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/util",
"//third_party:dagger",
"//third_party:guava",
"//third_party:guice",
"//third_party:joda_time",
"//third_party:jsr305",
"//third_party:jsr330_inject",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.testing.junit.runner.junit4;

import com.google.common.base.Preconditions;
import com.google.inject.Singleton;
import com.google.testing.junit.junit4.runner.MemoizingRequest;
import com.google.testing.junit.junit4.runner.RunNotifierWrapper;

Expand All @@ -24,9 +25,6 @@
import org.junit.runner.notification.RunNotifier;
import org.junit.runner.notification.StoppedByUserException;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
* Creates requests that can be cancelled.
*/
Expand All @@ -36,9 +34,6 @@ class CancellableRequestFactory {
private volatile ThreadSafeRunNotifier currentNotifier;
private volatile boolean cancelRequested = false;

@Inject
CancellableRequestFactory() {}

/**
* Creates a request that can be cancelled. Can only be called once.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class JUnit4Runner {
private final PrintStream testRunnerOut;
private final JUnit4Config config;
private final Set<RunListener> runListeners;
private final Set<Initializer> initializers;

private GoogleTestSecurityManager googleTestSecurityManager;
private SecurityManager previousSecurityManager;
Expand All @@ -60,21 +59,15 @@ public class JUnit4Runner {
* Creates a runner.
*/
@Inject
JUnit4Runner(
Request request,
CancellableRequestFactory requestFactory,
Supplier<TestSuiteModel> modelSupplier,
@Stdout PrintStream testRunnerOut,
JUnit4Config config,
Set<RunListener> runListeners,
Set<Initializer> initializers) {
private JUnit4Runner(Request request, CancellableRequestFactory requestFactory,
Supplier<TestSuiteModel> modelSupplier, @Stdout PrintStream testRunnerOut,
JUnit4Config config, Set<RunListener> runListeners) {
this.request = request;
this.requestFactory = requestFactory;
this.modelSupplier = modelSupplier;
this.config = config;
this.testRunnerOut = testRunnerOut;
this.runListeners = runListeners;
this.initializers = initializers;
}

/**
Expand All @@ -86,10 +79,6 @@ public Result run() {
testRunnerOut.println("JUnit4 Test Runner");
checkJUnitRunnerApiVersion();

for (Initializer init : initializers) {
init.initialize();
}

// Sharding
TestSuiteModel model = modelSupplier.get();
Filter shardingFilter = model.getShardingFilter();
Expand Down Expand Up @@ -272,15 +261,4 @@ public Description getDescription() {
public void run(RunNotifier notifier) {
}
}

/**
* A simple initializer which can be used to provide additional initialization logic in custom
* runners.
*
* <p>Initializers will be run in unspecified order. If an exception is thrown it will not be
* deemed recoverable and will cause the runner to error-out.
*/
public interface Initializer {
void initialize();
}
}
Loading

0 comments on commit 6f418ed

Please sign in to comment.