From a4bfb3c49f164d47322b39c560a716b89788002b Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 26 May 2016 19:01:21 +0000 Subject: Convert the Bazel JUnit4 test runner from Guice to Dagger. -- MOS_MIGRATED_REVID=123342439 --- .../java/com/google/testing/junit/runner/BUILD | 2 +- .../testing/junit/runner/BazelTestRunner.java | 63 +++++++++------- .../google/testing/junit/runner/junit4/Args.java | 31 ++++++++ .../com/google/testing/junit/runner/junit4/BUILD | 2 +- .../runner/junit4/CancellableRequestFactory.java | 7 +- .../junit/runner/junit4/JUnit4InstanceModules.java | 88 ++++++++++++++++++++++ .../testing/junit/runner/junit4/JUnit4Runner.java | 28 ++++++- .../runner/junit4/JUnit4RunnerBaseModule.java | 69 ++++++++--------- .../junit/runner/junit4/JUnit4RunnerModule.java | 82 ++++++++------------ .../runner/junit4/JUnit4TestModelBuilder.java | 2 +- .../runner/junit4/JUnit4TestNameListener.java | 7 +- .../junit4/JUnit4TestStackTraceListener.java | 5 +- .../junit/runner/junit4/JUnit4TestXmlListener.java | 7 +- .../junit/runner/model/AntXmlResultWriter.java | 5 ++ .../com/google/testing/junit/runner/sharding/BUILD | 2 +- .../junit/runner/sharding/ShardingEnvironment.java | 5 ++ .../junit/runner/sharding/ShardingFilters.java | 9 ++- 17 files changed, 278 insertions(+), 136 deletions(-) create mode 100644 src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java create mode 100644 src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java (limited to 'src/java_tools/junitrunner') 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 78ed2d18c6..b99b06c55c 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 efde522c57..0e39d265b3 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,29 +14,30 @@ 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. * @@ -142,13 +143,21 @@ public class BazelTestRunner { } } - Injector injector = Guice.createInjector( - new BazelTestRunnerModule(suite, ImmutableList.copyOf(args))); - - JUnit4Runner runner = injector.getInstance(JUnit4Runner.class); + JUnit4Runner runner = + DaggerBazelTestRunner_JUnit4Bazel.builder() + .suiteClass(new SuiteClass(suite)) + .config(new Config(args)) + .build() + .runner(); return runner.run().wasSuccessful() ? 0 : 1; } + @Singleton + @Component(modules = {BazelTestRunnerModule.class}) + interface JUnit4Bazel { + JUnit4Runner runner(); + } + private static Class getTestClass(String name) { if (name == null) { return null; @@ -181,29 +190,25 @@ public class BazelTestRunner { thread.start(); } - static class BazelTestRunnerModule extends AbstractModule { - final Class suite; - final List args; - - BazelTestRunnerModule(Class suite, List args) { - this.suite = suite; - this.args = args; - } - - @Override - protected void configure() { - install(JUnit4RunnerModule.create(suite, args)); - bind(XmlResultWriter.class).to(AntXmlResultWriter.class); + @Module(includes = JUnit4RunnerModule.class) + static class BazelTestRunnerModule { + @Provides + static XmlResultWriter resultWriter(AntXmlResultWriter impl) { + return impl; } - @Provides @Singleton @Stdout - PrintStream provideStdoutStream() { + @Provides + @Singleton + @Stdout + static PrintStream stdoutStream() { return System.out; } - @Provides @Singleton @Stderr - PrintStream provideStderrStream() { + @Provides + @Singleton + @Stderr + static PrintStream stderrStream() { 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 new file mode 100644 index 0000000000..9093891307 --- /dev/null +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/Args.java @@ -0,0 +1,31 @@ +// 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} 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 0141b76a3c..f5f2ecd855 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 e8991662e0..371f0bd71d 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,7 +15,6 @@ 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; @@ -25,6 +24,9 @@ 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. */ @@ -34,6 +36,9 @@ 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 new file mode 100644 index 0000000000..966478df83 --- /dev/null +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java @@ -0,0 +1,88 @@ +// 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 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.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 4134131216..10447a7b70 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,6 +51,7 @@ public class JUnit4Runner { private final PrintStream testRunnerOut; private final JUnit4Config config; private final Set runListeners; + private final Set initializers; private GoogleTestSecurityManager googleTestSecurityManager; private SecurityManager previousSecurityManager; @@ -59,15 +60,21 @@ public class JUnit4Runner { * Creates a runner. */ @Inject - private JUnit4Runner(Request request, CancellableRequestFactory requestFactory, - Supplier modelSupplier, @Stdout PrintStream testRunnerOut, - JUnit4Config config, Set runListeners) { + JUnit4Runner( + Request request, + CancellableRequestFactory requestFactory, + Supplier modelSupplier, + @Stdout PrintStream testRunnerOut, + JUnit4Config config, + Set runListeners, + Set initializers) { this.request = request; this.requestFactory = requestFactory; this.modelSupplier = modelSupplier; this.config = config; this.testRunnerOut = testRunnerOut; this.runListeners = runListeners; + this.initializers = initializers; } /** @@ -79,6 +86,10 @@ public class JUnit4Runner { testRunnerOut.println("JUnit4 Test Runner"); checkJUnitRunnerApiVersion(); + for (Initializer init : initializers) { + init.initialize(); + } + // Sharding TestSuiteModel model = modelSupplier.get(); Filter shardingFilter = model.getShardingFilter(); @@ -261,4 +272,15 @@ public class JUnit4Runner { public void run(RunNotifier notifier) { } } + + /** + * A simple initializer which can be used to provide additional initialization logic in custom + * runners. + * + *

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 28e6466067..c6742324a3 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,50 +37,44 @@ 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; /** - * Guice module for creating {@link JUnit4Runner}. This contains the common + * Dagger module for creating a {@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. * - *

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. */ -class JUnit4RunnerBaseModule extends AbstractModule { - private final Class suiteClass; +@Module(includes = SuiteClass.class) +public final class JUnit4RunnerBaseModule { - public JUnit4RunnerBaseModule(Class suiteClass) { - this.suiteClass = suiteClass; + @Multibindings + interface MultiBindings { + Set initializers(); } - @Override - protected void configure() { - requireBinding(Key.get(PrintStream.class, Stdout.class)); - requireBinding(JUnit4Config.class); - requireBinding(TestSuiteModel.Builder.class); - - // 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()); + @Provides + static ShardingFilterFactory shardingFilterFactory() { + return DEFAULT_SHARDING_STRATEGY; + } - // Bind listeners - Multibinder listenerBinder = newSetBinder(binder(), RunListener.class); - listenerBinder.addBinding().to(TextListener.class); + @Provides(type = SET) + static RunListener textListener(TextListener impl) { + return impl; } - @Provides @Singleton - Supplier provideTestSuiteModelSupplier(JUnit4TestModelBuilder builder) { + + @Provides + @Singleton + static Supplier provideTestSuiteModelSupplier(JUnit4TestModelBuilder builder) { return Suppliers.memoize(builder); } - @Provides @Singleton - TextListener provideTextListener(@Stdout PrintStream testRunnerOut) { + @Provides + @Singleton + static TextListener provideTextListener(@Stdout PrintStream testRunnerOut) { return new TextListener(asUtf8PrintStream(testRunnerOut)); } @@ -92,8 +86,9 @@ class JUnit4RunnerBaseModule extends AbstractModule { } } - @Provides @Singleton - Request provideRequest() { + @Provides + @Singleton + static Request provideRequest(@TopLevelSuite Class suiteClass) { /* * 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 5f15524808..91cfd1d875 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,73 +14,61 @@ package com.google.testing.junit.runner.junit4; -import static com.google.inject.multibindings.Multibinder.newSetBinder; +import static dagger.Provides.Type.SET; 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 java.util.List; + +import javax.inject.Singleton; /** - * Guice module for real test runs. + * Dagger module for real test runs. */ -public class JUnit4RunnerModule extends AbstractModule { - private final Class suite; - private final JUnit4Config config; - private final ImmutableList unparsedArgs; - - public static JUnit4RunnerModule create(Class suite, List args) { - JUnit4Options options = JUnit4Options.parse(System.getenv(), ImmutableList.copyOf(args)); - JUnit4Config config = new JUnit4Config( - options.getTestIncludeFilter(), - options.getTestExcludeFilter(), - Optional.absent()); - return new JUnit4RunnerModule(suite, config, ImmutableList.copyOf(options.getUnparsedArgs())); +@Module(includes = {JUnit4RunnerBaseModule.class, JUnit4InstanceModules.Config.class}) +public final class JUnit4RunnerModule { + @Provides + static Ticker ticker() { + return Ticker.systemTicker(); } - private JUnit4RunnerModule( - Class suite, JUnit4Config config, ImmutableList unparsedArgs) { - this.suite = suite; - this.config = config; - this.unparsedArgs = unparsedArgs; + @Provides + static SignalHandlers.HandlerInstaller signalHandlerInstaller() { + return SignalHandlers.createRealHandlerInstaller(); } - @Override - protected void configure() { - install(new JUnit4RunnerBaseModule(suite)); - - // We require explicit bindings so we don't use an unexpected just-in-time binding - bind(SignalHandlers.class); + @Provides(type = SET) + static RunListener nameListener(JUnit4TestNameListener impl) { + return impl; + } - // Normal bindings - bind(JUnit4Config.class).toInstance(config); - bind(Ticker.class).toInstance(Ticker.systemTicker()); - bind(SignalHandlers.HandlerInstaller.class).toInstance( - SignalHandlers.createRealHandlerInstaller()); + @Provides(type = SET) + static RunListener xmlListener(JUnit4TestXmlListener impl) { + return impl; + } - // Bind listeners - Multibinder listenerBinder = newSetBinder(binder(), RunListener.class); - listenerBinder.addBinding().to(JUnit4TestNameListener.class); - listenerBinder.addBinding().to(JUnit4TestXmlListener.class); - listenerBinder.addBinding().to(JUnit4TestStackTraceListener.class); + @Provides(type = SET) + static RunListener stackTraceListener(JUnit4TestStackTraceListener impl) { + return impl; } - @Provides @Singleton @Xml - OutputStream provideXmlStream() { + + @Provides + @Singleton + @Xml + static OutputStream provideXmlStream(JUnit4Config config) { Optional path = config.getXmlOutputPath(); if (path.isPresent()) { @@ -103,16 +91,10 @@ public class JUnit4RunnerModule extends AbstractModule { @Provides @Singleton SettableCurrentRunningTest provideCurrentRunningTest() { return new SettableCurrentRunningTest() { + @Override void setGlobalTestNameProvider(TestNameProvider provider) { testNameProvider = provider; } }; } - - /** - * Gets the list of unparsed command line arguments. - */ - public ImmutableList 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 62df88db45..5dd98e9b3b 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,7 +16,6 @@ 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; @@ -24,6 +23,7 @@ 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 b7da73fa53..e1c2c54133 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,15 +14,16 @@ 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 abb0614afd..8f62b1d99f 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,8 +14,6 @@ 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; @@ -28,6 +26,9 @@ 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 5e572e1e10..609591bb8d 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,8 +15,6 @@ 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; @@ -33,12 +31,15 @@ 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 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 d2ead679c4..29d983ac4a 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,6 +25,8 @@ 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 @@ -59,6 +61,9 @@ 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 43a7d05201..e442368437 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 6d3836fadd..366f25a662 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,6 +20,8 @@ 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 @@ -35,6 +37,9 @@ 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 206a8e9a1d..e149a74007 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,7 +14,6 @@ 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; @@ -22,6 +21,8 @@ import org.junit.runner.manipulation.Filter; import java.util.Collection; +import javax.inject.Inject; + /** * A factory for test sharding filters. */ @@ -54,7 +55,7 @@ public class ShardingFilters { } } } - + public static final ShardingFilterFactory DEFAULT_SHARDING_STRATEGY = ShardingStrategy.ROUND_ROBIN; private final ShardingEnvironment shardingEnvironment; @@ -104,9 +105,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; } } -- cgit v1.2.3