+
Skip to content

Improve Fixture handling #268

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 14 commits into from
Jun 2, 2018
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
70 changes: 29 additions & 41 deletions src/main/java/org/concordion/Concordion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.concordion.api.*;
import org.concordion.internal.FixtureType;
import org.concordion.internal.SpecificationToSpecificationByExampleAdaptor;
import org.concordion.internal.SpecificationType;
import org.concordion.internal.SummarizingResultRecorder;
Expand All @@ -17,22 +18,6 @@ public class Concordion {
private SpecificationByExample specification;
private String specificationDescription;

/**
* @deprecated use {@link #Concordion(List, SpecificationLocator, SpecificationReader, EvaluatorFactory, Fixture)} instead
* @param specificationLocator locates the specification based on the specification type
* @param specificationReader specification reader
* @param evaluatorFactory evaluator factory
* @param fixture fixture instance
* @throws IOException on i/o error
*/
@Deprecated
public Concordion(SpecificationLocator specificationLocator, SpecificationReader specificationReader, EvaluatorFactory evaluatorFactory, Fixture fixture) throws IOException {
this.specificationReader = specificationReader;
this.evaluatorFactory = evaluatorFactory;

resource = specificationLocator.locateSpecification(fixture.getFixtureObject());
}

/**
* Constructor. Locates the specification with a type from the <code>specificationTypes</code> list.
* Errors if unable to find exactly one specification of all the specified types.
Expand All @@ -41,27 +26,27 @@ public Concordion(SpecificationLocator specificationLocator, SpecificationReader
* @param specificationLocator locates the specification based on the specification type
* @param specificationReader specification reader
* @param evaluatorFactory evaluator factory
* @param fixture fixture instance
* @param fixtureType
* @throws IOException on i/o error
*/
public Concordion(List<SpecificationType> specificationTypes, SpecificationLocator specificationLocator, SpecificationReader specificationReader, EvaluatorFactory evaluatorFactory, Fixture fixture) throws IOException {
public Concordion(List<SpecificationType> specificationTypes, SpecificationLocator specificationLocator, SpecificationReader specificationReader, EvaluatorFactory evaluatorFactory, FixtureType fixtureType) throws IOException {
this.specificationReader = specificationReader;
this.evaluatorFactory = evaluatorFactory;

SpecificationType specificationType = null;

for (SpecificationType currentType : specificationTypes) {
Resource currentResource = specificationLocator.locateSpecification(fixture.getFixtureObject(), currentType.getTypeSuffix());
Resource currentResource = specificationLocator.locateSpecification(fixtureType, currentType.getTypeSuffix());
if (specificationReader.canFindSpecification(currentResource)) {
if (specificationType != null) {
throw new RuntimeException(createMultipleSpecsMessage(fixture, specificationType, currentType));
throw new RuntimeException(createMultipleSpecsMessage(fixtureType, specificationType, currentType));
}
specificationType = currentType;
resource = currentResource;
}
}
if (specificationType == null) {
throw new RuntimeException(createUnableToFindSpecMessage(fixture, specificationTypes));
throw new RuntimeException(createUnableToFindSpecMessage(fixtureType, specificationTypes));
}
specificationReader.setSpecificationConverter(specificationType.getConverter());
}
Expand All @@ -77,73 +62,76 @@ public void override(Resource resource) throws IOException {

public ResultSummary process(Fixture fixture) throws IOException {
SummarizingResultRecorder resultRecorder = new SummarizingResultRecorder();
resultRecorder.setSpecificationDescription(fixture.getSpecificationDescription());
getSpecification(fixture).process(evaluatorFactory.createEvaluator(fixture.getFixtureObject()), resultRecorder, fixture);
Evaluator evaluator = evaluatorFactory.createEvaluator(fixture.getFixtureObject());
getSpecification().process(evaluator, resultRecorder, fixture);
return resultRecorder;
}

private SpecificationByExample getSpecification(Fixture fixture) throws IOException {
private SpecificationByExample getSpecification() throws IOException {
if (specification == null) {
specification = loadSpecificationFromResource(fixture, resource);
specificationDescription = specification.getSpecificationDescription();
specification = loadSpecificationFromResource(resource);
specificationDescription = specification.getDescription();
}
return specification;
}

public List<String> getExampleNames(Fixture fixture) throws IOException {
return getSpecification(fixture).getExampleNames();
public List<String> getExampleNames(FixtureType fixtureType) throws IOException {
List<String> exampleNames = getSpecification().getExampleNames();
if (exampleNames.isEmpty()) {
exampleNames.add(fixtureType.getDescription());
}
return exampleNames;
}

public boolean hasExampleCommands(Fixture fixture) throws IOException {
return getSpecification(fixture).hasExampleCommandNodes();
public boolean hasExampleCommands() throws IOException {
return getSpecification().hasExampleCommandNodes();
}

public ResultSummary processExample(Fixture fixture, String example) throws IOException {
SummarizingResultRecorder resultRecorder = new SummarizingResultRecorder(example);
getSpecification(fixture).processExample(evaluatorFactory.createEvaluator(fixture.getFixtureObject()), example, resultRecorder, fixture);
Evaluator evaluator = evaluatorFactory.createEvaluator(fixture.getFixtureObject());
getSpecification().processExample(evaluator, example, resultRecorder, fixture);
return resultRecorder;
}

/**
* Loads the specification for the specified fixture.
*
* @param fixture the fixture instance
* @param resource the resource to load
* @return a SpecificationByExample object to use
* @throws IOException if the resource cannot be loaded
*/
private SpecificationByExample loadSpecificationFromResource(Fixture fixture, Resource resource) throws IOException {
Specification specification= specificationReader.readSpecification(resource);
private SpecificationByExample loadSpecificationFromResource(Resource resource) throws IOException {
Specification specification = specificationReader.readSpecification(resource);

SpecificationByExample specificationByExample;
if (specification instanceof SpecificationByExample) {
specificationByExample = (SpecificationByExample) specification;
} else {
specificationByExample = new SpecificationToSpecificationByExampleAdaptor(specification);
}
specificationByExample.setFixture(fixture);
return specificationByExample;
}

public void finish() {
specification.finish();
}

public void checkValidStatus(Fixture fixture) throws IOException {
if (getSpecification(fixture).hasExampleCommandNodes() && fixture.getDeclaredImplementationStatus() != ImplementationStatus.EXPECTED_TO_PASS) {
public void checkValidStatus(FixtureType fixtureType) throws IOException {
if (hasExampleCommands() && fixtureType.getDeclaredImplementationStatus() != ImplementationStatus.EXPECTED_TO_PASS) {
throw new IllegalStateException("Error: When the specification contains examples, "
+ "the Implementation Status (ExpectedToFail or Unimplemented) must be set on the example command in the specification, "
+ "and not as an annotation on the fixture.");
}
}

private String createMultipleSpecsMessage(Fixture fixture, SpecificationType type1, SpecificationType type2) {
String fixturePathWithoutSuffix = fixture.getFixturePathWithoutSuffix();
private String createMultipleSpecsMessage(FixtureType fixtureType, SpecificationType type1, SpecificationType type2) {
String fixturePathWithoutSuffix = fixtureType.getFixturePathWithoutSuffix();
return SimpleFormatter.format("Found multiple matching specifications: '%s.%s' and '%s.%s'",
fixturePathWithoutSuffix, type1.getTypeSuffix(), fixturePathWithoutSuffix, type2.getTypeSuffix());
}

private String createUnableToFindSpecMessage(Fixture fixture, List<SpecificationType> specificationTypes) {
private String createUnableToFindSpecMessage(FixtureType fixtureType, List<SpecificationType> specificationTypes) {
String msg = "Unable to find specification: '";
boolean first = true;
for (SpecificationType specificationType : specificationTypes) {
Expand All @@ -152,7 +140,7 @@ private String createUnableToFindSpecMessage(Fixture fixture, List<Specification
} else {
msg += "' or '";
}
msg += fixture.getFixturePathWithoutSuffix() + "." + specificationType.getTypeSuffix();
msg += fixtureType.getFixturePathWithoutSuffix() + "." + specificationType.getTypeSuffix();
}
msg += "'";
return msg;
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/org/concordion/api/Fixture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.concordion.api;

import org.concordion.internal.FixtureType;

import java.io.File;
import java.util.List;

Expand All @@ -8,38 +10,17 @@
*
* @since 2.0.0
*/
public interface Fixture extends FixtureDeclarations {
public interface Fixture {

/**
* @return the fixture instance.
*/
Object getFixtureObject();

/**
* @return the class of the fixture instance.
*/
Class<?> getFixtureClass();

/**
* @return a list of the absolute paths on the class path.
*/
List<File> getClassPathRoots();

/**
* @return the fixture class and all of its superclasses, excluding java.lang.Object,
* ordered from the most super class to the fixture class.
*/
List<Class<?>> getClassHierarchyParentFirst();

/**
* @return a description of the specification containing the fixture name.
*/
String getSpecificationDescription();

/**
* @return the absolute path to the fixture, omitting the suffix.
* @return the FixtureType, which is a wrapper around the fixtureObject's class.
*/
String getFixturePathWithoutSuffix();
FixtureType getFixtureType();

/**
* Setup the fixture for the next run, hence the need to pass in a fixture object.
Expand Down
28 changes: 5 additions & 23 deletions src/main/java/org/concordion/api/ResultSummary.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.concordion.api;

import org.concordion.internal.FixtureType;

import java.io.PrintStream;

public interface ResultSummary {

/**
* @deprecated As of release 2.0, replaced by {@link #assertIsSatisfied(Fixture fixture)}
* @param fixture fixture instance
*/
@Deprecated void assertIsSatisfied(Object fixture);

void assertIsSatisfied(Fixture fixture);
void assertIsSatisfied(FixtureType fixtureType);

boolean hasExceptions();

Expand All @@ -22,23 +18,9 @@ public interface ResultSummary {

long getIgnoredCount();

/**
* @deprecated As of release 2.0, replaced by {@link #print(PrintStream, Fixture)}
* @param out stream to print result summary to
* @param fixture fixture instance
*/
@Deprecated void print(PrintStream out, Object fixture);

void print(PrintStream out, Fixture fixture);

/**
* @deprecated As of release 2.0, replaced by {@link #printCountsToString(Fixture)}
* @param fixture fixture instance
* @return string containing results
*/
@Deprecated String printCountsToString(Object fixture);
void print(PrintStream out, FixtureType fixtureType);

String printCountsToString(Fixture fixture);
String printCountsToString(FixtureType fixtureType);

String getSpecificationDescription();

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/concordion/api/Specification.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
public interface Specification {

void process(Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture);

/**
* Gets the description of the exported specification.
*
* @return specification description
*/
String getDescription();
}
17 changes: 1 addition & 16 deletions src/main/java/org/concordion/api/SpecificationByExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,13 @@
*/
public interface SpecificationByExample extends Specification {

/**
* Sets the fixture. Will be called before the other methods are called so that
* the class can process the fixture to determine examples, etc.
*
* @param fixture the fixture instance
*/
void setFixture(Fixture fixture);

/**
* Returns whether the specification contains example nodes.
*
* @return true if specification has one or more nodes with an example command on
*/
boolean hasExampleCommandNodes();

/**
* Gets the description of the exported specification.
*
* @return specification description
*/
String getSpecificationDescription();

/**
* Gets all the examples in the specification.
*
Expand All @@ -40,7 +25,7 @@ public interface SpecificationByExample extends Specification {

/**
* Processes a single example.
* @param evaluator evaluator
* @param evaluator evaluator
* @param example name of the example
* @param resultRecorder result recorder
* @param fixture the example's fixture
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/org/concordion/api/SpecificationLocator.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package org.concordion.api;

import org.concordion.internal.FixtureType;

public interface SpecificationLocator {
/**
* @deprecated - use {@link #locateSpecification(Object, String)} instead
* Locates the specification for the named fixture, assuming a fixed type suffix (eg. HTML).
* @param fixture the fixture to find the specification for
* @return the resource for the specification, which may or may not actually exist
*/
@Deprecated
Resource locateSpecification(Object fixture);

/**
* Locates a specification, allowing the type suffix of the specification to be specified.
* @param fixtureObject the fixture to find the specification for
* @param fixtureType the fixture type to find the specification for
* @param typeSuffix the suffix of the specification
* @return the resource for the specification, which may or may not actually exist
*
* @since 2.0.0
*/
Resource locateSpecification(Object fixtureObject, String typeSuffix);
Resource locateSpecification(FixtureType fixtureType, String typeSuffix);
}
10 changes: 0 additions & 10 deletions src/main/java/org/concordion/api/SpecificationLocatorWithType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import junit.framework.TestCase;

import org.concordion.api.Fixture;
import org.concordion.internal.ClassNameAndTypeBasedSpecificationLocator;
import org.concordion.internal.ClassNameBasedSpecificationLocator;
import org.concordion.internal.FixtureInstance;
import org.concordion.internal.FixtureRunner;

Expand All @@ -20,7 +20,7 @@ public void testProcessSpecification() throws Throwable {
Fixture fixture = new FixtureInstance(this);
fixture.beforeSpecification();
fixture.setupForRun(this);
new FixtureRunner(fixture, new ClassNameAndTypeBasedSpecificationLocator()).run(fixture);
new FixtureRunner(fixture, new ClassNameBasedSpecificationLocator()).run(fixture);
fixture.afterSpecification();
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载