Skip to content

Commit

Permalink
[Core] Remove deprecated TypeRegistryConfigurer
Browse files Browse the repository at this point in the history
Prefer using the annotation based method of providing parameters instead.
For example:

```gherkin
Feature: Parameter Types

  Scenario: flights
    Given LHR-CDG has been delayed 45 minutes
```

```java

    @given("{flight} has been delayed {int} minutes")
    public void lhrCDGHasBeenDelayedMinutes(Flight flight, int delay) {
        assertEquals("LHR", flight.from);
        assertEquals("CDG", flight.to);
        assertEquals(45, delay);
    }

    @ParameterType(value = "([A-Z]{3})-([A-Z]{3})", useForSnippets = true)
    public Flight flight(String from, String to) {
        return new Flight(from, to);
    }
```
  • Loading branch information
mpkorstanje committed Aug 10, 2021
1 parent 2fcd4b1 commit acea42d
Show file tree
Hide file tree
Showing 23 changed files with 28 additions and 353 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
* [Core] Removed `--strict` and `--no-strict` options ([#1788](https://github.com/cucumber/cucumber-jvm/issues/1788) M.P. Korstanje)
- Cucumber executes scenarios in strict mode by default
* [Core] Removed deprecated `TypeRegistryConfigurer` ([#2356](https://github.com/cucumber/cucumber-jvm/issues/2356) M.P. Korstanje)
- Use `@ParameterType` instead.
* [Weld] Removed `cucumber-weld` ([#2276](https://github.com/cucumber/cucumber-jvm/issues/2276) M.P. Korstanje)
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.
* [Needle] Removed `cucumber-needled` ([#2276](https://github.com/cucumber/cucumber-jvm/issues/2276) M.P. Korstanje)
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.

### Fixed
* [Core] Emit step hook messages ([#2009](https://github.com/cucumber/cucumber-jvm/issues/2093) Grasshopper)

Expand Down

This file was deleted.

16 changes: 4 additions & 12 deletions core/src/main/java/io/cucumber/core/runner/Runner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.cucumber.core.runner;

import io.cucumber.core.api.TypeRegistryConfigurer;
import io.cucumber.core.backend.Backend;
import io.cucumber.core.backend.CucumberBackendException;
import io.cucumber.core.backend.CucumberInvocationTargetException;
Expand Down Expand Up @@ -40,19 +39,16 @@ public final class Runner {
private final Collection<? extends Backend> backends;
private final Options runnerOptions;
private final ObjectFactory objectFactory;
private final TypeRegistryConfigurer typeRegistryConfigurer;
private List<SnippetGenerator> snippetGenerators;

public Runner(
EventBus bus, Collection<? extends Backend> backends, ObjectFactory objectFactory,
TypeRegistryConfigurer typeRegistryConfigurer, Options runnerOptions
EventBus bus, Collection<? extends Backend> backends, ObjectFactory objectFactory, Options runnerOptions
) {
this.bus = bus;
this.runnerOptions = runnerOptions;
this.backends = backends;
this.glue = new CachingGlue(bus);
this.objectFactory = objectFactory;
this.typeRegistryConfigurer = typeRegistryConfigurer;
List<URI> gluePaths = runnerOptions.getGlue();
log.debug(() -> "Loading glue from " + gluePaths);
for (Backend backend : backends) {
Expand Down Expand Up @@ -84,13 +80,9 @@ public void runPickle(Pickle pickle) {
}

private StepTypeRegistry createTypeRegistryForPickle(Pickle pickle) {
Locale locale = typeRegistryConfigurer.locale();
if (locale == null) {
locale = new Locale(pickle.getLanguage());
}
StepTypeRegistry stepTypeRegistry = new StepTypeRegistry(locale);
typeRegistryConfigurer.configureTypeRegistry(stepTypeRegistry);
return stepTypeRegistry;
String language = pickle.getLanguage();
Locale locale = new Locale(language);
return new StepTypeRegistry(locale);
}

public void runBeforeAllHooks() {
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/io/cucumber/core/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,9 @@ public Runtime build() {
plugins.setEventBusOnEventListenerPlugins(eventBus);
}

final TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(
classLoader, runtimeOptions);

final RunnerSupplier runnerSupplier = runtimeOptions.isMultiThreaded()
? new ThreadLocalRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier,
typeRegistryConfigurerSupplier)
: new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier,
typeRegistryConfigurerSupplier);
? new ThreadLocalRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier)
: new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier);

final ExecutorService executor = runtimeOptions.isMultiThreaded()
? Executors.newFixedThreadPool(runtimeOptions.getThreads(), new CucumberThreadFactory())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ public final class SingletonRunnerSupplier implements RunnerSupplier {
private final Options runnerOptions;
private final EventBus eventBus;
private final ObjectFactorySupplier objectFactorySupplier;
private final TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier;
private Runner runner;

public SingletonRunnerSupplier(
Options runnerOptions,
EventBus eventBus,
BackendSupplier backendSupplier,
ObjectFactorySupplier objectFactorySupplier, TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier
ObjectFactorySupplier objectFactorySupplier
) {
this.backendSupplier = backendSupplier;
this.runnerOptions = runnerOptions;
this.eventBus = eventBus;
this.objectFactorySupplier = objectFactorySupplier;
this.typeRegistryConfigurerSupplier = typeRegistryConfigurerSupplier;
}

@Override
Expand All @@ -44,7 +42,6 @@ private Runner createRunner() {
eventBus,
backendSupplier.get(),
objectFactorySupplier.get(),
typeRegistryConfigurerSupplier.get(),
runnerOptions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@ public final class ThreadLocalRunnerSupplier implements RunnerSupplier {
private final io.cucumber.core.runner.Options runnerOptions;
private final SynchronizedEventBus sharedEventBus;
private final ObjectFactorySupplier objectFactorySupplier;
private final TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier;

private final ThreadLocal<Runner> runners = ThreadLocal.withInitial(this::createRunner);

public ThreadLocalRunnerSupplier(
Options runnerOptions,
EventBus sharedEventBus,
BackendSupplier backendSupplier,
ObjectFactorySupplier objectFactorySupplier,
TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier
ObjectFactorySupplier objectFactorySupplier
) {
this.runnerOptions = runnerOptions;
this.sharedEventBus = SynchronizedEventBus.synchronize(sharedEventBus);
this.backendSupplier = backendSupplier;
this.objectFactorySupplier = objectFactorySupplier;
this.typeRegistryConfigurerSupplier = typeRegistryConfigurerSupplier;
}

@Override
Expand All @@ -48,7 +45,6 @@ private Runner createRunner() {
new LocalEventBus(sharedEventBus),
backendSupplier.get(),
objectFactorySupplier.get(),
typeRegistryConfigurerSupplier.get(),
runnerOptions);
}

Expand Down

This file was deleted.

11 changes: 3 additions & 8 deletions core/src/test/java/io/cucumber/core/runner/HookTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.cucumber.core.runner;

import io.cucumber.core.api.TypeRegistryConfigurer;
import io.cucumber.core.backend.Backend;
import io.cucumber.core.backend.Glue;
import io.cucumber.core.backend.HookDefinition;
Expand All @@ -21,7 +20,6 @@
import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -51,7 +49,6 @@ void after_hooks_execute_before_objects_are_disposed() {
ObjectFactory objectFactory = mock(ObjectFactory.class);
final HookDefinition hook = mock(HookDefinition.class);
when(hook.getLocation()).thenReturn("hook-location");
TypeRegistryConfigurer typeRegistryConfigurer = mock(TypeRegistryConfigurer.class);
when(hook.getTagExpression()).thenReturn("");

doAnswer(invocation -> {
Expand All @@ -60,8 +57,7 @@ void after_hooks_execute_before_objects_are_disposed() {
return null;
}).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());

Runner runner = new Runner(bus, Collections.singleton(backend), objectFactory, typeRegistryConfigurer,
runtimeOptions);
Runner runner = new Runner(bus, Collections.singleton(backend), objectFactory, runtimeOptions);

runner.runPickle(pickle);

Expand All @@ -78,8 +74,6 @@ void hook_throws_exception_with_name_when_tag_expression_is_invalid() {
ObjectFactory objectFactory = mock(ObjectFactory.class);
final HookDefinition hook = mock(HookDefinition.class);
when(hook.getLocation()).thenReturn("hook-location");
TypeRegistryConfigurer typeRegistryConfigurer = mock(TypeRegistryConfigurer.class);

when(hook.getTagExpression()).thenReturn("(");

doAnswer(invocation -> {
Expand All @@ -89,10 +83,11 @@ void hook_throws_exception_with_name_when_tag_expression_is_invalid() {
}).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());

RuntimeException e = assertThrows(RuntimeException.class,
() -> new Runner(bus, Collections.singleton(backend), objectFactory, typeRegistryConfigurer,
() -> new Runner(bus, Collections.singleton(backend), objectFactory,
runtimeOptions));

assertThat(e.getMessage(),
is("Invalid tag expression at 'hook-location'"));
}

}
Loading

0 comments on commit acea42d

Please sign in to comment.