-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the new tag-expressions library, but support both the use of the new tag expression syntax and the old tag expression syntax.
- Loading branch information
1 parent
ecfc554
commit e14c980
Showing
20 changed files
with
288 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cucumber.runtime; | ||
|
||
import gherkin.pickles.Pickle; | ||
import gherkin.pickles.PickleTag; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TagPredicateOld implements PicklePredicate { | ||
private TagExpressionOld tagExpression; | ||
|
||
public TagPredicateOld(List<String> tags) { | ||
this.tagExpression = new TagExpressionOld(tags); | ||
} | ||
|
||
@Override | ||
public boolean apply(Pickle pickle) { | ||
List<PickleTag> tags; | ||
try { // TODO: Fix when Gherkin provide a getter for the tags. | ||
Field f; | ||
f = pickle.getClass().getDeclaredField("tags"); | ||
f.setAccessible(true); | ||
tags = (List<PickleTag>) f.get(pickle); | ||
} catch (Exception e) { | ||
tags = Collections.<PickleTag>emptyList(); | ||
} | ||
return apply(tags); | ||
} | ||
|
||
public boolean apply(Collection<PickleTag> pickleTags) { | ||
if (tagExpression.evaluate(pickleTags)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
119 changes: 119 additions & 0 deletions
119
core/src/test/java/cucumber/runtime/TagPredicateOldTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package cucumber.runtime; | ||
|
||
import gherkin.pickles.Pickle; | ||
import gherkin.pickles.PickleLocation; | ||
import gherkin.pickles.PickleStep; | ||
import gherkin.pickles.PickleTag; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class TagPredicateOldTest { | ||
private static final String NAME = "pickle_name"; | ||
private static final List<PickleStep> NO_STEPS = Collections.<PickleStep>emptyList(); | ||
private static final PickleLocation MOCK_LOCATION = mock(PickleLocation.class); | ||
private static final String FOO_TAG_VALUE = "@FOO"; | ||
private static final PickleTag FOO_TAG = new PickleTag(MOCK_LOCATION, FOO_TAG_VALUE); | ||
private static final String BAR_TAG_VALUE = "@BAR"; | ||
private static final PickleTag BAR_TAG = new PickleTag(MOCK_LOCATION, BAR_TAG_VALUE); | ||
private static final String NOT_FOO_TAG_VALUE = "~@FOO"; | ||
private static final String FOO_OR_BAR_TAG_VALUE = "@FOO,@BAR"; | ||
|
||
@Test | ||
public void empty_tag_predicate_matches_pickle_with_any_tags() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(Collections.<String>emptyList()); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void single_tag_predicate_does_not_match_pickle_with_no_tags() { | ||
Pickle pickle = createPickleWithTags(Collections.<PickleTag>emptyList()); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE)); | ||
|
||
assertFalse(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void single_tag_predicate_matches_pickle_with_same_single_tag() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void single_tag_predicate_matches_pickle_with_more_tags() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG, BAR_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void single_tag_predicate_does_not_match_pickle_with_different_single_tag() { | ||
Pickle pickle = createPickleWithTags(asList(BAR_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE)); | ||
|
||
assertFalse(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void not_tag_predicate_matches_pickle_with_no_tags() { | ||
Pickle pickle = createPickleWithTags(Collections.<PickleTag>emptyList()); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(NOT_FOO_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void not_tag_predicate_does_not_match_pickle_with_same_single_tag() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(NOT_FOO_TAG_VALUE)); | ||
|
||
assertFalse(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void not_tag_predicate_matches_pickle_with_different_single_tag() { | ||
Pickle pickle = createPickleWithTags(asList(BAR_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(NOT_FOO_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void and_tag_predicate_matches_pickle_with_all_tags() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG, BAR_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE, BAR_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void and_tag_predicate_does_not_match_pickle_with_one_of_the_tags() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_TAG_VALUE, BAR_TAG_VALUE)); | ||
|
||
assertFalse(predicate.apply(pickle)); | ||
} | ||
|
||
@Test | ||
public void or_tag_predicate_matches_pickle_with_one_of_the_tags() { | ||
Pickle pickle = createPickleWithTags(asList(FOO_TAG)); | ||
TagPredicateOld predicate = new TagPredicateOld(asList(FOO_OR_BAR_TAG_VALUE)); | ||
|
||
assertTrue(predicate.apply(pickle)); | ||
} | ||
|
||
private Pickle createPickleWithTags(List<PickleTag> tags) { | ||
return new Pickle(NAME, NO_STEPS, tags, asList(MOCK_LOCATION)); | ||
} | ||
} |
Oops, something went wrong.