Skip to content
Permalink
Browse files

consolidate ServiceUtils and ServiceLoaderUtils

  • Loading branch information...
MykolaGolubyev committed May 7, 2019
1 parent 4374eb9 commit f87e43a7a1faa6c7ec9860abcb779766dfbbb9c6
Showing with 40 additions and 66 deletions.
  1. +2 −1 webtau-browser/src/main/java/com/twosigma/webtau/browser/driver/WebDriverCreatorListeners.java
  2. +2 −2 webtau-browser/src/main/java/com/twosigma/webtau/browser/navigation/BrowserPageNavigation.java
  3. +1 −1 ...src/main/java/com/twosigma/webtau/browser/page/value/handlers/PageElementGetSetValueHandlers.java
  4. +2 −2 webtau-config/src/main/java/com/twosigma/webtau/cfg/WebTauConfig.java
  5. +2 −1 webtau-console/src/main/java/com/twosigma/webtau/console/ConsoleOutputs.java
  6. +3 −2 ...re-groovy/src/main/groovy/com/twosigma/webtau/data/time/listener/TimeRangeContextListeners.groovy
  7. +3 −3 webtau-core/src/main/java/com/twosigma/webtau/data/converters/ToMapConverters.java
  8. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/data/math/DynamicMath.java
  9. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/data/render/DataRenderers.java
  10. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/expectation/ExpectationHandlers.java
  11. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/expectation/contain/ContainAnalyzer.java
  12. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/expectation/equality/CompareToComparator.java
  13. +2 −2 webtau-core/src/main/java/com/twosigma/webtau/expectation/timer/ExpectationTimerConfigProvider.java
  14. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/reporter/StepReporters.java
  15. +1 −1 webtau-core/src/main/java/com/twosigma/webtau/reporter/TestResultPayloadExtractors.java
  16. +0 −31 webtau-core/src/main/java/com/twosigma/webtau/utils/ServiceUtils.java
  17. +2 −2 webtau-http/src/main/java/com/twosigma/webtau/http/config/HttpConfigurations.java
  18. +2 −2 webtau-http/src/main/java/com/twosigma/webtau/http/validation/HttpValidationHandlers.java
  19. +2 −1 webtau-report/src/main/java/com/twosigma/webtau/report/ReportDataProviders.java
  20. +2 −1 webtau-report/src/main/java/com/twosigma/webtau/report/ReportGenerators.java
  21. +1 −1 ...unner-groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestListeners.groovy
  22. +2 −2 webtau-utils/src/main/java/com/twosigma/webtau/utils/ServiceLoaderUtils.java
@@ -19,10 +19,11 @@
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import org.openqa.selenium.WebDriver;

import java.util.List;
import java.util.Set;

public class WebDriverCreatorListeners {
private static final Set<WebDriverCreatorListener> listeners =
private static final List<WebDriverCreatorListener> listeners =
ServiceLoaderUtils.load(WebDriverCreatorListener.class);

private WebDriverCreatorListeners() {
@@ -16,15 +16,15 @@

package com.twosigma.webtau.browser.navigation;

import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import org.openqa.selenium.WebDriver;

import java.util.List;

public class BrowserPageNavigation {
private static final ThreadLocal<Boolean> handlersEnabled = ThreadLocal.withInitial(() -> true);
private static final List<BrowserPageNavigationHandler> handlers =
ServiceUtils.discover(BrowserPageNavigationHandler.class);
ServiceLoaderUtils.load(BrowserPageNavigationHandler.class);

public static void addHandler(BrowserPageNavigationHandler handler) {
handlers.add(handler);
@@ -28,7 +28,7 @@
import java.util.stream.Stream;

public class PageElementGetSetValueHandlers {
private static final Set<PageElementGetSetValueHandler> discovered =
private static final List<PageElementGetSetValueHandler> discovered =
ServiceLoaderUtils.load(PageElementGetSetValueHandler.class);
private static final List<PageElementGetSetValueHandler> added = new ArrayList<>();

@@ -339,7 +339,7 @@ static String convertToCamelCase(String key) {
private static WebTauConfig INSTANCE = new WebTauConfig();
}

private static ArrayList<WebTauConfigHandler> discoverConfigHandlers() {
return new ArrayList<>(ServiceLoaderUtils.load(WebTauConfigHandler.class));
private static List<WebTauConfigHandler> discoverConfigHandlers() {
return ServiceLoaderUtils.load(WebTauConfigHandler.class);
}
}
@@ -19,13 +19,14 @@
import com.twosigma.webtau.console.ansi.AnsiConsoleOutput;
import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

public class ConsoleOutputs {
private static final ConsoleOutput defaultOutput = new AnsiConsoleOutput();

private static final Set<ConsoleOutput> outputs = ServiceLoaderUtils.load(ConsoleOutput.class);
private static final List<ConsoleOutput> outputs = ServiceLoaderUtils.load(ConsoleOutput.class);

public static void out(Object... styleOrValues) {
getOutputsStream().forEach(o -> o.out(styleOrValues));
@@ -17,10 +17,11 @@
package com.twosigma.webtau.data.time.listener

import com.twosigma.webtau.data.time.TestTime
import com.twosigma.webtau.utils.ServiceUtils
import com.twosigma.webtau.utils.ServiceLoaderUtils

class TimeRangeContextListeners {
// TODO multithread support
private static List<TimeRangeContextListener> listeners = ServiceUtils.discover(TimeRangeContextListener)
private static List<TimeRangeContextListener> listeners = ServiceLoaderUtils.load(TimeRangeContextListener)

static void clear() {
listeners.clear()
@@ -16,11 +16,11 @@

package com.twosigma.webtau.data.converters;

import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;
import java.util.Map;

import com.twosigma.webtau.utils.ServiceUtils;

public class ToMapConverters {
private static List<ToMapConverter> converters = discover();

@@ -29,7 +29,7 @@
}

private static List<ToMapConverter> discover() {
List<ToMapConverter> discovered = ServiceUtils.discover(ToMapConverter.class);
List<ToMapConverter> discovered = ServiceLoaderUtils.load(ToMapConverter.class);
discovered.add(new MapToMapConverter());
discovered.add(new BeanToMapConverter());

@@ -1,7 +1,7 @@
package com.twosigma.webtau.data.math;

import com.twosigma.webtau.data.render.DataRenderers;
import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import com.twosigma.webtau.utils.TraceUtils;

import java.util.List;
@@ -27,7 +27,7 @@ private static SimpleMathHandler findAddSubtractMathHandler(Object left, Object
}

private static List<SimpleMathHandler> discoverSimpleMathHandlers() {
return ServiceUtils.discover(SimpleMathHandler.class);
return ServiceLoaderUtils.load(SimpleMathHandler.class);
}

private static RuntimeException noAddSubtractHandlerFound(Object left, Object right) {
@@ -16,7 +16,7 @@

package com.twosigma.webtau.data.render;

import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import com.twosigma.webtau.utils.TraceUtils;

import java.util.ArrayList;
@@ -37,7 +37,7 @@ public static String render(Object data) {
private static List<DataRenderer> discover() {
List<DataRenderer> renders = new ArrayList<>();
renders.add(new NullRenderer());
renders.addAll(ServiceUtils.discover(DataRenderer.class));
renders.addAll(ServiceLoaderUtils.load(DataRenderer.class));
renders.add(new ByteArrayRenderer());
renders.add(new TableDataRenderer());
renders.add(new StringRenderer());
@@ -17,15 +17,15 @@
package com.twosigma.webtau.expectation;

import com.twosigma.webtau.expectation.ExpectationHandler.Flow;
import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class ExpectationHandlers {
private static List<ExpectationHandler> globalHandlers = ServiceUtils.discover(ExpectationHandler.class);
private static List<ExpectationHandler> globalHandlers = ServiceLoaderUtils.load(ExpectationHandler.class);
private static ThreadLocal<List<ExpectationHandler>> localHandlers = ThreadLocal.withInitial(ArrayList::new);

public static void add(ExpectationHandler handler) {
@@ -20,7 +20,7 @@
import com.twosigma.webtau.expectation.ActualPath;
import com.twosigma.webtau.expectation.contain.handlers.NullContainHandler;
import com.twosigma.webtau.expectation.equality.ActualPathMessage;
import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import com.twosigma.webtau.utils.TraceUtils;

import java.util.ArrayList;
@@ -84,7 +84,7 @@ private boolean contains(Object actual, Object expected, Consumer<ContainHandler
private static List<ContainHandler> discoverHandlers() {
List<ContainHandler> result = new ArrayList<>();
result.add(new NullContainHandler());
result.addAll(ServiceUtils.discover(ContainHandler.class));
result.addAll(ServiceLoaderUtils.load(ContainHandler.class));

return result;
}
@@ -20,7 +20,7 @@
import com.twosigma.webtau.expectation.ActualPath;
import com.twosigma.webtau.expectation.equality.handlers.AnyCompareToHandler;
import com.twosigma.webtau.expectation.equality.handlers.NullCompareToHandler;
import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;
import com.twosigma.webtau.utils.TraceUtils;

import java.util.ArrayList;
@@ -304,7 +304,7 @@ private static CompareToHandler findCompareToGreaterLessHandler(Object actual, O
private static List<CompareToHandler> discoverHandlers() {
List<CompareToHandler> result = new ArrayList<>();

List<CompareToHandler> discovered = ServiceUtils.discover(CompareToHandler.class);
List<CompareToHandler> discovered = ServiceLoaderUtils.load(CompareToHandler.class);

discovered.stream().filter(CompareToHandler::handleNulls).forEach(result::add);
result.add(new NullCompareToHandler());
@@ -16,12 +16,12 @@

package com.twosigma.webtau.expectation.timer;

import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;

public class ExpectationTimerConfigProvider {
private static List<ExpectationTimerConfig> configs = ServiceUtils.discover(ExpectationTimerConfig.class);
private static List<ExpectationTimerConfig> configs = ServiceLoaderUtils.load(ExpectationTimerConfig.class);

public static ExpectationTimer createExpectationTimer() {
validate();
@@ -29,7 +29,7 @@
private static final StepReporter defaultStepReporter =
new ConsoleStepReporter(IntegrationTestsMessageBuilder.getConverter());

private static Set<StepReporter> reporters = Collections.synchronizedSet(
private static List<StepReporter> reporters = Collections.synchronizedList(
ServiceLoaderUtils.load(StepReporter.class));

private static ThreadLocal<List<StepReporter>> localReporters = ThreadLocal.withInitial(ArrayList::new);
@@ -25,7 +25,7 @@
import java.util.stream.Stream;

public class TestResultPayloadExtractors {
private static final Set<TestResultPayloadExtractor> extractors = Collections.synchronizedSet(
private static final List<TestResultPayloadExtractor> extractors = Collections.synchronizedList(
ServiceLoaderUtils.load(TestResultPayloadExtractor.class));

public static Stream<TestResultPayload> extract(Stream<TestStep<?, ?>> testSteps) {

This file was deleted.

Oops, something went wrong.
@@ -17,7 +17,7 @@
package com.twosigma.webtau.http.config;

import com.twosigma.webtau.http.HttpHeader;
import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.Collections;
import java.util.List;
@@ -27,7 +27,7 @@
private static final ThreadLocal<Boolean> enabled = ThreadLocal.withInitial(() -> true);

private static final List<HttpConfiguration> configurations = Collections.synchronizedList(
ServiceUtils.discover(HttpConfiguration.class));
ServiceLoaderUtils.load(HttpConfiguration.class));

public static void add(HttpConfiguration configuration) {
configurations.add(configuration);
@@ -16,12 +16,12 @@

package com.twosigma.webtau.http.validation;

import com.twosigma.webtau.utils.ServiceUtils;
import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;

public class HttpValidationHandlers {
private static final List<HttpValidationHandler> configurations = ServiceUtils.discover(HttpValidationHandler.class);
private static final List<HttpValidationHandler> configurations = ServiceLoaderUtils.load(HttpValidationHandler.class);

public static void validate(HttpValidationResult validationResult) {
configurations.forEach(c -> c.validate(validationResult));
@@ -18,11 +18,12 @@

import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

public class ReportDataProviders {
private static final Set<ReportDataProvider> providers = ServiceLoaderUtils.load(ReportDataProvider.class);
private static final List<ReportDataProvider> providers = ServiceLoaderUtils.load(ReportDataProvider.class);

public static Stream<ReportCustomData> provide(ReportTestEntries testEntries) {
return providers.stream().flatMap(e -> e.provide(testEntries));
@@ -18,10 +18,11 @@

import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;
import java.util.Set;

public class ReportGenerators {
private static final Set<ReportGenerator> generators = ServiceLoaderUtils.load(ReportGenerator.class);
private static final List<ReportGenerator> generators = ServiceLoaderUtils.load(ReportGenerator.class);

public static void generate(Report report) {
generators.forEach(g -> g.generate(report));
@@ -21,7 +21,7 @@ import com.twosigma.webtau.utils.ServiceLoaderUtils
import java.nio.file.Path

class StandaloneTestListeners {
private static Set<StandaloneTestListener> listeners = Collections.synchronizedSet(
private static List<StandaloneTestListener> listeners = Collections.synchronizedList(
ServiceLoaderUtils.load(StandaloneTestListener))

static void add(StandaloneTestListener listener) {
@@ -22,9 +22,9 @@
private ServiceLoaderUtils() {
}

public static <E> Set<E> load(Class<E> serviceClass) {
public static <E> List<E> load(Class<E> serviceClass) {
ServiceLoader<E> loader = ServiceLoader.load(serviceClass);
Set<E> result = new LinkedHashSet<>();
List<E> result = new ArrayList<>();
loader.forEach(result::add);

return result;

0 comments on commit f87e43a

Please sign in to comment.
You can’t perform that action at this time.