Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Groovy Example | ||
|
||
copied from cuke4duke groovy example | ||
|
||
|
||
## Running Example | ||
|
||
mvn test |
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,40 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-jvm</artifactId> | ||
<relativePath>../../pom.xml</relativePath> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>groovy-calculator</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Examples: Groovy Calculator</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-groovy</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-all</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
16 changes: 16 additions & 0 deletions
16
examples/groovy-calculator/src/main/java/calc/Calculator.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,16 @@ | ||
package calc; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Calculator { | ||
List<Double> stack = new ArrayList<Double>(); | ||
|
||
public void push(double arg) { | ||
stack.add(arg); | ||
} | ||
|
||
public double divide() { | ||
return stack.get(0) / stack.get(1); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/groovy-calculator/src/test/java/calc/DivisionTest.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,12 @@ | ||
package calc; | ||
|
||
import cucumber.junit.Cucumber; | ||
import cucumber.junit.Feature; | ||
import org.junit.runner.RunWith; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
@RunWith(Cucumber.class) | ||
@Feature(value = "division.feature") | ||
public class DivisionTest { | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/groovy-calculator/src/test/resources/division.feature
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,17 @@ | ||
# language: en | ||
Feature: Division | ||
In order to avoid silly mistakes | ||
Cashiers must be able to calculate a fraction | ||
|
||
@important | ||
Scenario: Regular numbers | ||
Given I have entered 3 into the calculator | ||
And I have entered 2 into the calculator | ||
When I press divide | ||
Then the stored result should be 1.5 | ||
|
||
Scenario: More numbers | ||
Given I have entered 6 into the calculator | ||
And I have entered 3 into the calculator | ||
When I press divide | ||
Then the stored result should be 2.0 |
44 changes: 44 additions & 0 deletions
44
examples/groovy-calculator/src/test/resources/step_definitions/CalculatorSteps.groovy
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,44 @@ | ||
import calc.Calculator | ||
|
||
this.metaClass.mixin(cucumber.runtime.groovy.Hooks) | ||
this.metaClass.mixin(cucumber.runtime.groovy.EN) | ||
|
||
|
||
class CustomWorld { | ||
String customMethod() { | ||
"foo" | ||
} | ||
} | ||
|
||
World { | ||
new CustomWorld() | ||
} | ||
|
||
Before() { | ||
assert "foo" == customMethod() | ||
calc = new Calculator() | ||
} | ||
|
||
Before("@notused") { | ||
throw new RuntimeException("Never happens") | ||
} | ||
|
||
Before("@notused,@important", "@alsonotused") { | ||
throw new RuntimeException("Never happens") | ||
} | ||
|
||
Given(~"I have entered (\\d+) into (.*) calculator") { int number, String ignore -> | ||
calc.push number | ||
} | ||
|
||
Given(~"(\\d+) into the") { -> | ||
throw new RuntimeException("should never get here since we're running with --guess") | ||
} | ||
|
||
When(~"I press (\\w+)") { String opname -> | ||
result = calc."$opname"() | ||
} | ||
|
||
Then(~"the stored result should be (.*)") { double expected -> | ||
assert expected == result | ||
} |
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