Skip to content

Clean up public API #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2017
Merged
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
3 changes: 1 addition & 2 deletions core/src/main/java/cucumber/api/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cucumber.runtime.CucumberException;
import cucumber.runtime.ParameterInfo;
import cucumber.runtime.table.DiffableRow;
import cucumber.runtime.table.TableConverter;
import cucumber.runtime.table.TableDiffException;
import cucumber.runtime.table.TableDiffer;
import cucumber.runtime.table.TablePrinter;
Expand Down Expand Up @@ -42,7 +41,7 @@ public static DataTable create(List<?> raw, Locale locale, String... columnNames

private static DataTable create(List<?> raw, Locale locale, String format, String... columnNames) {
ParameterInfo parameterInfo = new ParameterInfo(null, format, null, null);
TableConverter tableConverter = new TableConverter(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(locale), parameterInfo);
TableConverter tableConverter = new cucumber.runtime.table.TableConverter(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(locale), parameterInfo);
return tableConverter.toTable(raw, columnNames);
}

Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/cucumber/api/TableConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cucumber.api;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public interface TableConverter {
<T> T convert(DataTable dataTable, Type type, boolean transposed);

<T> List<T> toList(DataTable dataTable, Type itemType);

<T> List<List<T>> toLists(DataTable dataTable, Type itemType);

<K, V> Map<K, V> toMap(DataTable dataTable, Type keyType, Type valueType);

<K, V> List<Map<K, V>> toMaps(DataTable dataTable, Type keyType, Type valueType);

DataTable toTable(List<?> objects, String... columnNames);
}
28 changes: 28 additions & 0 deletions core/src/main/java/cucumber/api/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,40 @@ public class TestCase {
private final List<TestStep> testSteps;
private final boolean dryRun;

/**
* Creates a new instance of a test case.
*
* @param testSteps of the test case
* @param pickleEvent the pickle executed by this test case
* @deprecated not part of the public api
*/
@Deprecated
public TestCase(List<TestStep> testSteps, PickleEvent pickleEvent) {
this(testSteps, pickleEvent, false);
}

/**
* Creates a new instance of a test case.
*
* @param testSteps of the test case
* @param pickleEvent the pickle executed by this test case
* @param dryRun skip execution of the test steps
* @deprecated not part of the public api
*/
@Deprecated
public TestCase(List<TestStep> testSteps, PickleEvent pickleEvent, boolean dryRun) {
this.testSteps = testSteps;
this.pickleEvent = pickleEvent;
this.dryRun = dryRun;
}

/**
* Executes the test case.
*
* @param bus to which events should be broadcast
* @deprecated not part of the public api
*/
@Deprecated
public void run(EventBus bus) {
boolean skipNextStep = this.dryRun;
Long startTime = bus.getTime();
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/cucumber/api/TestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,24 @@ public abstract class TestStep {
"org.junit.AssumptionViolatedException",
"org.junit.internal.AssumptionViolatedException"
};

static {
Arrays.sort(ASSUMPTION_VIOLATED_EXCEPTIONS);
}

/**
* @deprecated not part of the public api
*/
@Deprecated
protected final DefinitionMatch definitionMatch;

/**
* Creates a new test step from the matching step definition
*
* @param definitionMatch the matching step definition
* @deprecated not part of the public api
*/
@Deprecated
public TestStep(DefinitionMatch definitionMatch) {
this.definitionMatch = definitionMatch;
}
Expand Down Expand Up @@ -52,6 +65,15 @@ public List<cucumber.runtime.Argument> getDefinitionArgument() {

public abstract HookType getHookType();

/**
* @param bus to which events should be broadcast
* @param language in which the step is defined
* @param scenario of which this step is part
* @param skipSteps if this step should be skipped
* @return result of running this step
* @deprecated not part of the public api
*/
@Deprecated
public Result run(EventBus bus, String language, Scenario scenario, boolean skipSteps) {
Long startTime = bus.getTime();
bus.send(new TestStepStarted(startTime, this));
Expand All @@ -69,10 +91,12 @@ public Result run(EventBus bus, String language, Scenario scenario, boolean skip
return result;
}

@Deprecated
protected Result.Type nonExceptionStatus(boolean skipSteps) {
return skipSteps ? Result.Type.SKIPPED : Result.Type.PASSED;
}

@Deprecated
protected Result.Type executeStep(String language, Scenario scenario, boolean skipSteps) throws Throwable {
if (!skipSteps) {
definitionMatch.runStep(language, scenario);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runtime/StepDefinitionMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cucumber.api.DataTable;
import cucumber.api.Scenario;
import cucumber.runtime.table.TableConverter;
import cucumber.api.TableConverter;
import cucumber.runtime.xstream.LocalizedXStreams;
import cucumber.util.Mapper;
import gherkin.pickles.PickleCell;
Expand Down Expand Up @@ -100,7 +100,7 @@ private ParameterInfo getParameterType(int n, Type argumentType) {

private Object tableArgument(PickleTable stepArgument, int argIndex, LocalizedXStreams.LocalizedXStream xStream) {
ParameterInfo parameterInfo = getParameterType(argIndex, DataTable.class);
TableConverter tableConverter = new TableConverter(xStream, parameterInfo);
TableConverter tableConverter = new cucumber.runtime.table.TableConverter(xStream, parameterInfo);
DataTable table = new DataTable(stepArgument, tableConverter);
Type type = parameterInfo.getType();
return tableConverter.convert(table, type, parameterInfo.isTransposed());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cucumber.runtime.table;

import cucumber.api.DataTable;
import cucumber.api.TableConverter;
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleTable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* This class converts a {@link cucumber.api.DataTable} to various other types.
*/
public class TableConverter {
public class TableConverter implements cucumber.api.TableConverter {
private final LocalizedXStreams.LocalizedXStream xStream;
private final ParameterInfo parameterInfo;

Expand All @@ -55,6 +55,7 @@ public TableConverter(LocalizedXStreams.LocalizedXStream xStream, ParameterInfo
* @param transposed whether the table should be transposed first.
* @return the transformed object.
*/
@Override
public <T> T convert(DataTable dataTable, Type type, boolean transposed) {
if (transposed) {
dataTable = dataTable.transpose();
Expand Down Expand Up @@ -117,6 +118,7 @@ private <T> List<T> toListOfComplexType(DataTable dataTable, Class<T> itemType)
}
}

@Override
public <T> List<T> toList(DataTable dataTable, Type itemType) {
SingleValueConverter itemConverter = xStream.getSingleValueConverter(itemType);
if (itemConverter != null) {
Expand All @@ -141,6 +143,7 @@ private <T> List<T> toList(DataTable dataTable, SingleValueConverter itemConvert
return Collections.unmodifiableList(result);
}

@Override
public <T> List<List<T>> toLists(DataTable dataTable, Type itemType) {
try {
xStream.setParameterInfo(parameterInfo);
Expand All @@ -163,6 +166,7 @@ public <T> List<List<T>> toLists(DataTable dataTable, Type itemType) {
}
}

@Override
public <K, V> Map<K, V> toMap(DataTable dataTable, Type keyType, Type valueType) {
try {
xStream.setParameterInfo(parameterInfo);
Expand All @@ -188,6 +192,7 @@ public <K, V> Map<K, V> toMap(DataTable dataTable, Type keyType, Type valueType)
}
}

@Override
public <K, V> List<Map<K, V>> toMaps(DataTable dataTable, Type keyType, Type valueType) {
try {
xStream.setParameterInfo(parameterInfo);
Expand Down Expand Up @@ -227,6 +232,7 @@ public <K, V> List<Map<K, V>> toMaps(DataTable dataTable, Type keyType, Type val
* @param columnNames an explicit list of column names
* @return a DataTable
*/
@Override
public DataTable toTable(List<?> objects, String... columnNames) {
try {
xStream.setParameterInfo(parameterInfo);
Expand Down