aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-05-27 17:25:16 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-05-30 09:19:26 +0000
commit6f418edf764a4dad4166ffcde49b0dbbc271214e (patch)
tree5c58d273abd04023ebc3b0617662eaf777c12d08 /src
parent2ce814bf7bb5b43a35dc445c395570e809b44db7 (diff)
Description redacted.
-- MOS_MIGRATED_REVID=123431237
Diffstat (limited to 'src')
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD2
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java63
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java31
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD2
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/CancellableRequestFactory.java7
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java88
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java28
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java69
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerModule.java82
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java2
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestNameListener.java7
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestStackTraceListener.java5
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java7
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java5
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/BUILD2
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingEnvironment.java5
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java9
17 files changed, 136 insertions, 278 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
index b99b06c55c..78ed2d18c6 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
@@ -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",
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
index 0e39d265b3..efde522c57 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BazelTestRunner.java
@@ -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.
*
@@ -143,19 +142,11 @@ public class BazelTestRunner {
}
}
- 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) {
@@ -190,25 +181,29 @@ public class BazelTestRunner {
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;
}
- }
+ };
}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java
deleted file mode 100644
index 9093891307..0000000000
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 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.testing.junit.runner.junit4;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Binding annotation that indicates that the given {@code Collection<String>} or
- * {@code String[]} represents the command-line arguments of the runner.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.PARAMETER, ElementType.METHOD})
-@Qualifier
-@interface Args {}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
index f5f2ecd855..0141b76a3c 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
@@ -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",
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/CancellableRequestFactory.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/CancellableRequestFactory.java
index 371f0bd71d..e8991662e0 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/CancellableRequestFactory.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/CancellableRequestFactory.java
@@ -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;
@@ -24,9 +25,6 @@ import org.junit.runner.Runner;
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.
*/
@@ -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.
*
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java
deleted file mode 100644
index 966478df83..0000000000
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2012 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.testing.junit.runner.junit4;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-
-import dagger.Module;
-import dagger.Provides;
-
-import java.nio.file.Path;
-
-import javax.inject.Singleton;
-
-/**
- * Dagger modules which hold state or are, for testing purposes, implemented with non-static
- * provider methods. These types are collected here so they can be cleanly named in the
- * component builder, but still be obvious in module includes and component declarations.
- */
-public final class JUnit4InstanceModules {
-
- /**
- * A stateful dagger module that holds the supplied test suite class.
- */
- @Module
- public static final class SuiteClass {
- private final Class<?> suiteClass;
-
- public SuiteClass(Class<?> suiteClass) {
- this.suiteClass = suiteClass;
- }
-
- @Provides
- @TopLevelSuite
- Class<?> topLevelSuite() {
- return suiteClass;
- }
-
- @Provides
- @TopLevelSuite
- static String topLevelSuiteName(@TopLevelSuite Class<?> suite) {
- return suite.getCanonicalName();
- }
- }
-
- /**
- * A module which supplies a JUnit4Config object, which can be overridden at test-time.
- */
- @Module
- public static final class Config {
- private final ImmutableList<String> args;
-
- /**
- * Creates a module that can provide a {@link JUnit4Config} from supplied command-line
- * arguments
- */
- public Config(String... args) {
- this.args = ImmutableList.copyOf(args);
- }
-
- @Provides
- @Singleton
- JUnit4Options options() {
- return JUnit4Options.parse(System.getenv(), ImmutableList.copyOf(args));
- }
-
- @Provides
- @Singleton
- JUnit4Config config(JUnit4Options options) {
- return new JUnit4Config(
- options.getTestIncludeFilter(), options.getTestExcludeFilter(), Optional.<Path>absent());
- }
- }
-
- private JUnit4InstanceModules() {}
-}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
index 10447a7b70..4134131216 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java
@@ -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;
@@ -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;
}
/**
@@ -86,10 +79,6 @@ public class JUnit4Runner {
testRunnerOut.println("JUnit4 Test Runner");
checkJUnitRunnerApiVersion();
- for (Initializer init : initializers) {
- init.initialize();
- }
-
// Sharding
TestSuiteModel model = modelSupplier.get();
Filter shardingFilter = model.getShardingFilter();
@@ -272,15 +261,4 @@ public class JUnit4Runner {
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();
- }
}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
index c6742324a3..28e6466067 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerBaseModule.java
@@ -14,21 +14,21 @@
package com.google.testing.junit.runner.junit4;
+import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static com.google.testing.junit.runner.sharding.ShardingFilters.DEFAULT_SHARDING_STRATEGY;
-import static dagger.Provides.Type.SET;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
import com.google.testing.junit.junit4.runner.MemoizingRequest;
import com.google.testing.junit.runner.internal.Stdout;
-import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.SuiteClass;
import com.google.testing.junit.runner.model.TestSuiteModel;
import com.google.testing.junit.runner.sharding.api.ShardingFilterFactory;
-import dagger.Module;
-import dagger.Multibindings;
-import dagger.Provides;
-
import org.junit.internal.TextListener;
import org.junit.runner.Request;
import org.junit.runner.notification.RunListener;
@@ -37,44 +37,50 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
-import java.util.Set;
-
-import javax.inject.Singleton;
/**
- * Dagger module for creating a {@link JUnit4Runner}. This contains the common
+ * Guice module for creating {@link JUnit4Runner}. This contains the common
* bindings used when either the runner runs actual tests or when we do
* integration tests of the runner itself.
*
+ * <p>Note: we do not use {@code Modules.override()} to test the runner because
+ * there are bindings that we use when the runner runs actual tests that set
+ * global state, and we don't want to do that when we test the runner itself.
*/
-@Module(includes = SuiteClass.class)
-public final class JUnit4RunnerBaseModule {
+class JUnit4RunnerBaseModule extends AbstractModule {
+ private final Class<?> suiteClass;
- @Multibindings
- interface MultiBindings {
- Set<JUnit4Runner.Initializer> initializers();
+ public JUnit4RunnerBaseModule(Class<?> suiteClass) {
+ this.suiteClass = suiteClass;
}
- @Provides
- static ShardingFilterFactory shardingFilterFactory() {
- return DEFAULT_SHARDING_STRATEGY;
- }
+ @Override
+ protected void configure() {
+ requireBinding(Key.get(PrintStream.class, Stdout.class));
+ requireBinding(JUnit4Config.class);
+ requireBinding(TestSuiteModel.Builder.class);
- @Provides(type = SET)
- static RunListener textListener(TextListener impl) {
- return impl;
- }
+ // We require explicit bindings so we don't use an unexpected just-in-time binding
+ bind(JUnit4Runner.class);
+ bind(JUnit4TestModelBuilder.class);
+ bind(CancellableRequestFactory.class);
+
+ // Normal bindings
+ bind(ShardingFilterFactory.class).toInstance(DEFAULT_SHARDING_STRATEGY);
+ bindConstant().annotatedWith(TopLevelSuite.class).to(suiteClass.getCanonicalName());
+ // Bind listeners
+ Multibinder<RunListener> listenerBinder = newSetBinder(binder(), RunListener.class);
+ listenerBinder.addBinding().to(TextListener.class);
+ }
- @Provides
- @Singleton
- static Supplier<TestSuiteModel> provideTestSuiteModelSupplier(JUnit4TestModelBuilder builder) {
+ @Provides @Singleton
+ Supplier<TestSuiteModel> provideTestSuiteModelSupplier(JUnit4TestModelBuilder builder) {
return Suppliers.memoize(builder);
}
- @Provides
- @Singleton
- static TextListener provideTextListener(@Stdout PrintStream testRunnerOut) {
+ @Provides @Singleton
+ TextListener provideTextListener(@Stdout PrintStream testRunnerOut) {
return new TextListener(asUtf8PrintStream(testRunnerOut));
}
@@ -86,9 +92,8 @@ public final class JUnit4RunnerBaseModule {
}
}
- @Provides
- @Singleton
- static Request provideRequest(@TopLevelSuite Class<?> suiteClass) {
+ @Provides @Singleton
+ Request provideRequest() {
/*
* JUnit4Runner requests the Runner twice, once to build the model (before
* filtering) and once to run the tests (after filtering). Constructing the
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerModule.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerModule.java
index 91cfd1d875..5f15524808 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerModule.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4RunnerModule.java
@@ -14,61 +14,73 @@
package com.google.testing.junit.runner.junit4;
-import static dagger.Provides.Type.SET;
+import static com.google.inject.multibindings.Multibinder.newSetBinder;
import com.google.common.base.Optional;
import com.google.common.base.Ticker;
+import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
import com.google.testing.junit.runner.internal.SignalHandlers;
import com.google.testing.junit.runner.util.TestNameProvider;
-import dagger.Module;
-import dagger.Provides;
-
import org.junit.runner.notification.RunListener;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.file.Path;
-
-import javax.inject.Singleton;
+import java.util.List;
/**
- * Dagger module for real test runs.
+ * Guice module for real test runs.
*/
-@Module(includes = {JUnit4RunnerBaseModule.class, JUnit4InstanceModules.Config.class})
-public final class JUnit4RunnerModule {
- @Provides
- static Ticker ticker() {
- return Ticker.systemTicker();
+public class JUnit4RunnerModule extends AbstractModule {
+ private final Class<?> suite;
+ private final JUnit4Config config;
+ private final ImmutableList<String> unparsedArgs;
+
+ public static JUnit4RunnerModule create(Class<?> suite, List<String> args) {
+ JUnit4Options options = JUnit4Options.parse(System.getenv(), ImmutableList.copyOf(args));
+ JUnit4Config config = new JUnit4Config(
+ options.getTestIncludeFilter(),
+ options.getTestExcludeFilter(),
+ Optional.<Path>absent());
+ return new JUnit4RunnerModule(suite, config, ImmutableList.copyOf(options.getUnparsedArgs()));
}
- @Provides
- static SignalHandlers.HandlerInstaller signalHandlerInstaller() {
- return SignalHandlers.createRealHandlerInstaller();
+ private JUnit4RunnerModule(
+ Class<?> suite, JUnit4Config config, ImmutableList<String> unparsedArgs) {
+ this.suite = suite;
+ this.config = config;
+ this.unparsedArgs = unparsedArgs;
}
- @Provides(type = SET)
- static RunListener nameListener(JUnit4TestNameListener impl) {
- return impl;
- }
+ @Override
+ protected void configure() {
+ install(new JUnit4RunnerBaseModule(suite));
- @Provides(type = SET)
- static RunListener xmlListener(JUnit4TestXmlListener impl) {
- return impl;
- }
+ // We require explicit bindings so we don't use an unexpected just-in-time binding
+ bind(SignalHandlers.class);
- @Provides(type = SET)
- static RunListener stackTraceListener(JUnit4TestStackTraceListener impl) {
- return impl;
- }
+ // Normal bindings
+ bind(JUnit4Config.class).toInstance(config);
+ bind(Ticker.class).toInstance(Ticker.systemTicker());
+ bind(SignalHandlers.HandlerInstaller.class).toInstance(
+ SignalHandlers.createRealHandlerInstaller());
+ // Bind listeners
+ Multibinder<RunListener> listenerBinder = newSetBinder(binder(), RunListener.class);
+ listenerBinder.addBinding().to(JUnit4TestNameListener.class);
+ listenerBinder.addBinding().to(JUnit4TestXmlListener.class);
+ listenerBinder.addBinding().to(JUnit4TestStackTraceListener.class);
+ }
- @Provides
- @Singleton
- @Xml
- static OutputStream provideXmlStream(JUnit4Config config) {
+ @Provides @Singleton @Xml
+ OutputStream provideXmlStream() {
Optional<Path> path = config.getXmlOutputPath();
if (path.isPresent()) {
@@ -91,10 +103,16 @@ public final class JUnit4RunnerModule {
@Provides @Singleton
SettableCurrentRunningTest provideCurrentRunningTest() {
return new SettableCurrentRunningTest() {
- @Override
void setGlobalTestNameProvider(TestNameProvider provider) {
testNameProvider = provider;
}
};
}
+
+ /**
+ * Gets the list of unparsed command line arguments.
+ */
+ public ImmutableList<String> getUnparsedArgs() {
+ return unparsedArgs;
+ }
}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
index 5dd98e9b3b..62df88db45 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilder.java
@@ -16,6 +16,7 @@ package com.google.testing.junit.runner.junit4;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
+import com.google.inject.Singleton;
import com.google.testing.junit.runner.model.TestSuiteModel;
import com.google.testing.junit.runner.model.TestSuiteModel.Builder;
@@ -23,7 +24,6 @@ import org.junit.runner.Description;
import org.junit.runner.Request;
import javax.inject.Inject;
-import javax.inject.Singleton;
/**
* Builds a {@link TestSuiteModel} for JUnit4 tests.
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestNameListener.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestNameListener.java
index e1c2c54133..b7da73fa53 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestNameListener.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestNameListener.java
@@ -14,16 +14,15 @@
package com.google.testing.junit.runner.junit4;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
import com.google.testing.junit.runner.util.TestNameProvider;
import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
/**
- * A listener to get the name of a JUnit4 test.
+ * A listener to get the name of a JUnit4 test.
*/
@Singleton
class JUnit4TestNameListener extends RunListener {
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestStackTraceListener.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestStackTraceListener.java
index 8f62b1d99f..abb0614afd 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestStackTraceListener.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestStackTraceListener.java
@@ -14,6 +14,8 @@
package com.google.testing.junit.runner.junit4;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
import com.google.testing.junit.runner.internal.SignalHandlers;
import com.google.testing.junit.runner.internal.StackTraces;
import com.google.testing.junit.runner.internal.Stderr;
@@ -26,9 +28,6 @@ import sun.misc.SignalHandler;
import java.io.PrintStream;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
/**
* A listener than dumps all stack traces when the test receives a SIGTERM.
*/
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
index 609591bb8d..5e572e1e10 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
@@ -15,6 +15,8 @@
package com.google.testing.junit.runner.junit4;
import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
import com.google.testing.junit.runner.internal.SignalHandlers;
import com.google.testing.junit.runner.internal.Stderr;
import com.google.testing.junit.runner.model.TestSuiteModel;
@@ -31,15 +33,12 @@ import sun.misc.SignalHandler;
import java.io.OutputStream;
import java.io.PrintStream;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
/**
* A listener that writes the test output as XML.
*/
@Singleton
class JUnit4TestXmlListener extends RunListener {
-
+
private final Supplier<TestSuiteModel> modelSupplier;
private final CancellableRequestFactory requestFactory;
private final SignalHandlers signalHandlers;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
index 29d983ac4a..d2ead679c4 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java
@@ -25,8 +25,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map.Entry;
-import javax.inject.Inject;
-
/**
* Writes the JUnit test nodes and their results into Ant-JUnit XML. Ant-JUnit XML is not a
* standardized format. For this implementation the
@@ -61,9 +59,6 @@ public final class AntXmlResultWriter implements XmlResultWriter {
private int testSuiteId;
- @Inject
- public AntXmlResultWriter() {}
-
@Override
public void writeTestSuites(XmlWriter writer, TestResult result) throws IOException {
testSuiteId = 0;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/BUILD
index e442368437..43a7d05201 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/BUILD
@@ -13,8 +13,8 @@ java_library(
srcs = glob(["*.java"]),
deps = [
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api",
- "//third_party:dagger",
"//third_party:guava",
+ "//third_party:guice",
"//third_party:jsr305",
"//third_party:junit4",
],
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingEnvironment.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingEnvironment.java
index 366f25a662..6d3836fadd 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingEnvironment.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingEnvironment.java
@@ -20,8 +20,6 @@ import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
-import javax.inject.Inject;
-
/**
* Utility class that encapsulates dependencies from sharding implementations
* on the test environment. See http://bazel.io/docs/test-sharding.html for a
@@ -37,9 +35,6 @@ public class ShardingEnvironment {
/** Usage: -Dtest.sharding.strategy=round_robin */
private static final String TEST_SHARDING_STRATEGY = "test.sharding.strategy";
- @Inject
- public ShardingEnvironment() {}
-
/**
* Return true iff the current test should be sharded.
*/
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
index e149a74007..206a8e9a1d 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
@@ -14,6 +14,7 @@
package com.google.testing.junit.runner.sharding;
+import com.google.inject.Inject;
import com.google.testing.junit.runner.sharding.api.ShardingFilterFactory;
import org.junit.runner.Description;
@@ -21,8 +22,6 @@ import org.junit.runner.manipulation.Filter;
import java.util.Collection;
-import javax.inject.Inject;
-
/**
* A factory for test sharding filters.
*/
@@ -55,7 +54,7 @@ public class ShardingFilters {
}
}
}
-
+
public static final ShardingFilterFactory DEFAULT_SHARDING_STRATEGY =
ShardingStrategy.ROUND_ROBIN;
private final ShardingEnvironment shardingEnvironment;
@@ -105,9 +104,9 @@ public class ShardingFilters {
} catch (ClassNotFoundException | InstantiationException |
IllegalAccessException | IllegalArgumentException e2) {
throw new RuntimeException(
- "Could not create custom sharding strategy class " + strategy, e2);
+ "Could not create custom sharding strategy class " + strategy, e2);
}
}
- return shardingFilterFactory;
+ return shardingFilterFactory;
}
}