Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions java/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
33 changes: 29 additions & 4 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>4.5.0</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>query</artifactId>
<version>14.6.1-SNAPSHOT</version>
<version>15.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber Query</name>
<description>Given one Cucumber Message, find another</description>
Expand Down Expand Up @@ -44,14 +44,22 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-bom</artifactId>
<version>3.27.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[29.0.1,31.0.0)</version>
<version>[31.0.0-SNAPSHOT,32.0.0)</version>
</dependency>

<dependency>
Expand All @@ -75,7 +83,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.6</version>
<scope>test</scope>
</dependency>

Expand All @@ -85,4 +92,22 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
19 changes: 10 additions & 9 deletions java/src/main/java/io/cucumber/query/Lineage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.cucumber.messages.types.Rule;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.TableRow;
import org.jspecify.annotations.Nullable;

import java.util.Objects;
import java.util.Optional;
Expand All @@ -23,13 +24,13 @@
public final class Lineage {

private final GherkinDocument document;
private final Feature feature;
private final Rule rule;
private final Scenario scenario;
private final Examples examples;
private final Integer examplesIndex;
private final TableRow example;
private final Integer exampleIndex;
private final @Nullable Feature feature;
private final @Nullable Rule rule;
private final @Nullable Scenario scenario;
private final @Nullable Examples examples;
private final @Nullable Integer examplesIndex;
private final @Nullable TableRow example;
private final @Nullable Integer exampleIndex;

Lineage(GherkinDocument document) {
this(document, null, null, null, null, null, null, null);
Expand All @@ -55,7 +56,7 @@ public final class Lineage {
this(parent.document, parent.feature, parent.rule, parent.scenario, parent.examples, parent.examplesIndex, example, exampleIndex);
}

private Lineage(GherkinDocument document, Feature feature, Rule rule, Scenario scenario, Examples examples, Integer examplesIndex, TableRow example, Integer exampleIndex) {
private Lineage(GherkinDocument document, @Nullable Feature feature, @Nullable Rule rule, @Nullable Scenario scenario, @Nullable Examples examples, @Nullable Integer examplesIndex, @Nullable TableRow example, @Nullable Integer exampleIndex) {
this.document = requireNonNull(document);
this.feature = feature;
this.rule = rule;
Expand Down Expand Up @@ -103,7 +104,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Lineage that = (Lineage) o;
return document.equals(that.document) && feature.equals(that.feature) && Objects.equals(rule, that.rule) && scenario.equals(that.scenario) && Objects.equals(examples, that.examples) && Objects.equals(example, that.example) && Objects.equals(examplesIndex, that.examplesIndex) && Objects.equals(exampleIndex, that.exampleIndex);
return document.equals(that.document) && Objects.equals(feature, that.feature) && Objects.equals(rule, that.rule) && Objects.equals(scenario, that.scenario) && Objects.equals(examples, that.examples) && Objects.equals(example, that.example) && Objects.equals(examplesIndex, that.examplesIndex) && Objects.equals(exampleIndex, that.exampleIndex);
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions java/src/main/java/io/cucumber/query/Lineages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

class Lineages {
final class Lineages {

private Lineages(){
// utility class
}

/**
* Create map of a {@link GherkinDocument} element to its {@link Lineage} in that document.
Expand Down
27 changes: 17 additions & 10 deletions java/src/main/java/io/cucumber/query/NamingCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.cucumber.query.NamingStrategy.ExampleName;
import io.cucumber.query.NamingStrategy.FeatureName;
import io.cucumber.query.NamingStrategy.Strategy;
import org.jspecify.annotations.Nullable;

import java.util.ArrayDeque;
import java.util.Deque;
Expand All @@ -25,7 +26,7 @@
*
* @see NamingStrategy
*/
class NamingCollector implements Collector<String> {
final class NamingCollector implements Collector<String> {

// There are at most 5 levels to a feature file.
private final Deque<String> parts = new ArrayDeque<>(5);
Expand All @@ -34,7 +35,7 @@ class NamingCollector implements Collector<String> {
private final FeatureName featureName;
private final ExampleName exampleName;

private String scenarioName;
private @Nullable String scenarioName;
private boolean isExample;
private int examplesIndex;

Expand All @@ -48,56 +49,62 @@ private NamingCollector(Strategy strategy, FeatureName featureName, ExampleName
this.exampleName = exampleName;
}

@Override
public void add(Feature feature) {
if (featureName == INCLUDE || strategy == SHORT) {
parts.add(feature.getName());
}
}

@Override
public void add(Rule rule) {
parts.add(rule.getName());
}

@Override
public void add(Scenario scenario) {
scenarioName = scenario.getName();
parts.add(scenarioName);
}

@Override
public void add(Examples examples, int index) {
parts.add(examples.getName());
this.examplesIndex = index;
}

@Override
public void add(TableRow example, int index) {
isExample = true;
parts.add("#" + (examplesIndex + 1) + "." + (index + 1));
}

@Override
public void add(Pickle pickle) {
String pickleName = pickle.getName();

// Case 0: Pickles with an empty a lineage
if (scenarioName == null){
if (scenarioName == null) {
parts.add(pickleName);
return;
}

// Case 1: Pickles from a scenario outline
if (isExample) {
switch (exampleName) {
case NUMBER:
break;
case NUMBER_AND_PICKLE_IF_PARAMETERIZED:
case NUMBER -> { }
case NUMBER_AND_PICKLE_IF_PARAMETERIZED -> {
boolean parameterized = !scenarioName.equals(pickleName);
if (parameterized) {
String exampleNumber = parts.removeLast();
parts.add(exampleNumber + ": " + pickleName);
}
break;
case PICKLE:
parts.removeLast(); // Remove example number
}
case PICKLE -> {
parts.removeLast();
// Remove example number
parts.add(pickleName);
break;
}
}
}
// Case 2: Pickles from a scenario
Expand Down
21 changes: 10 additions & 11 deletions java/src/main/java/io/cucumber/query/NamingStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.cucumber.messages.types.Pickle;

import static io.cucumber.query.LineageReducer.descending;
import static io.cucumber.query.NamingCollector.of;
import static io.cucumber.query.NamingStrategy.ExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED;
import static io.cucumber.query.NamingStrategy.FeatureName.INCLUDE;
import static java.util.Objects.requireNonNull;
Expand All @@ -26,10 +25,10 @@
*
* <pre>{@code
* Feature: Examples Tables
* Scenario Outline: Eating &lt;eat&gt; cucumbers
* Given there are &lt;start&gt; cucumbers
* When I eat &lt;eat&gt; cucumbers
* Then I should have &lt;left&gt; cucumbers
* Scenario Outline: Eating <eat> cucumbers
* Given there are <start> cucumbers
* When I eat <eat> cucumbers
* Then I should have <left> cucumbers
*
* Examples: These are passing
* | start | eat | left |
Expand All @@ -45,10 +44,10 @@
* With the long strategy, using example numbers and the pickle if
* parameterized, the pickles in this example would be named:
* <ul>
* <li>Examples Tables - Eating &lt;eat&gt; cucumbers - These are passing - #1.1: Eating 5 cucumbers
* <li>Examples Tables - Eating &lt;eat&gt; cucumbers - These are passing - #1.2: Eating 6 cucumbers
* <li>Examples Tables - Eating &lt;eat&gt; cucumbers - These are failing - #2.1: Eating 20 cucumbers
* <li>Examples Tables - Eating &lt;eat&gt; cucumbers - These are failing - #2.2: Eating 1 cucumbers
* <li>Examples Tables - Eating <eat> cucumbers - These are passing - #1.1: Eating 5 cucumbers
* <li>Examples Tables - Eating <eat> cucumbers - These are passing - #1.2: Eating 6 cucumbers
* <li>Examples Tables - Eating <eat> cucumbers - These are failing - #2.1: Eating 20 cucumbers
* <li>Examples Tables - Eating <eat> cucumbers - These are failing - #2.2: Eating 1 cucumbers
* </ul>
* <p>
* And with the short strategy, using pickle names:
Expand Down Expand Up @@ -112,7 +111,7 @@ private NamingStrategy() {
// Could be made a public interface if GherkinDocumentElements had a better API
}

public static class Builder {
public static final class Builder {

private final Strategy strategy;
private FeatureName featureName = INCLUDE;
Expand All @@ -133,7 +132,7 @@ public Builder featureName(FeatureName featureName) {
}

public NamingStrategy build() {
return new Adaptor(descending(of(strategy, featureName, exampleName)));
return new Adaptor(descending(NamingCollector.of(strategy, featureName, exampleName)));
}
}

Expand Down
9 changes: 7 additions & 2 deletions java/src/main/java/io/cucumber/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public Map<TestStepResultStatus, Long> countMostSevereTestStepResultStatus() {
.collect(groupingBy(identity(), LinkedHashMap::new, counting())));
return results;
}

public int countTestCasesStarted() {
return findAllTestCaseStarted().size();
}
Expand All @@ -101,8 +102,8 @@ public List<TestCaseStarted> findAllTestCaseStarted() {
.isPresent())
.collect(toList());
}
public List<StepDefinition> findAllStepDefinitions(){

public List<StepDefinition> findAllStepDefinitions() {
return new ArrayList<>(repository.stepDefinitionById.values());
}

Expand Down Expand Up @@ -195,6 +196,10 @@ public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseFinished
}

public Optional<Location> findLocationOf(Pickle pickle) {
Optional<Location> location = pickle.getLocation();
if (location.isPresent()) {
return location;
}
return findLineageBy(pickle).flatMap(lineage -> {
if (lineage.example().isPresent()) {
return lineage.example().map(TableRow::getLocation);
Expand Down
Loading
Loading