Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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
41 changes: 14 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,44 @@

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.10.RELEASE</version>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.7.02</version>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>3.0.0</version>
<artifactId>cucumber-java</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.0</version>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<!--
This (overriding) dependency can be removed post cucumber-jvm 3.0.0
It overrides the version specified by cucumber-jvm - 1.1.2 adds diffing.
-->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.2</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>pro-plugin</artifactId>
<version>2.1.1</version>
<artifactId>cucumber-picocontainer</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.10.RELEASE</version>
<scope>test</scope>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.15</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/shouty/Coordinate.java

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/java/shouty/PersonLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package shouty;

public class PersonLocation {
public String person;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be a good citizen - declare all immutable fields as final

public int x;
public int y;

public PersonLocation(String person_, int x_, int y_) {
person = person_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More idiomatic: this.person = person - don't use underscores.

x = x_;
y = y_;
}
}
20 changes: 20 additions & 0 deletions src/main/java/shouty/Shout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package shouty;

public class Shout {
public String person;
public String message;
public int x;
public int y;

public Shout(String person_, String message_) {
person = person_;
message = message_;
}

public Shout(String person_, String message_, int x_, int y_) {
person = person_;
message = message_;
x = x_;
y = y_;
}
}
39 changes: 0 additions & 39 deletions src/main/java/shouty/Shouty.java

This file was deleted.

35 changes: 35 additions & 0 deletions src/main/java/shouty/ShoutyServiceWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package shouty;

import kong.unirest.GenericType;
import kong.unirest.Unirest;

import java.util.List;

public class ShoutyServiceWrapper {

private static final String REST_ROOT_URI
= "https://virtserver.swaggerhub.com/smartbear/Shout/1.3.";

private String REST_URI;

public void chooseStubbedData(String dataSet) {
REST_URI = REST_ROOT_URI + dataSet;
}

public void setLocation(PersonLocation personLocation) {
// Unirest.post(REST_URI + "/shouts")
// .body(personLocation)
// .asEmpty();
}

public void shout(Shout shout) {
// Unirest.post(REST_URI + "/shouts")
// .body(shout)
// .asEmpty();
}

public List<Shout> getShouts() {
return Unirest.get(REST_URI + "/shouts").asObject(new GenericType<List<Shout>>() {
}).getBody();
}
}
29 changes: 0 additions & 29 deletions src/test/java/shouty/CoordinateTest.java

This file was deleted.

13 changes: 6 additions & 7 deletions src/test/java/shouty/RunCukesTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package shouty;

import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true, plugin = {"pretty", "html:target/cucumber", "rerun:target/rerun.txt", "json:target/cucumber.json", "io.cucumber.pro.JsonReporter"}, snippets = SnippetType.CAMELCASE)
@CucumberOptions(strict=true, plugin="pretty")
public class RunCukesTest {
// this is the adapter/bridge code
// between cucumber jvm and junit
// you do not need to edit this
// this is the adapter/bridge code
// between cucumber jvm and junit
// you do not need to edit this
}
51 changes: 30 additions & 21 deletions src/test/java/shouty/ShoutSteps.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package shouty;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.List;

import static java.util.Collections.emptyMap;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;

import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;


public class ShoutSteps {
private static final String ARBITRARY_MESSAGE = "Hello, world";
private final Shouty shouty = new Shouty();
private final ShoutyServiceWrapper shouty;
private List<Shout> shouts;

public ShoutSteps(ShoutyServiceWrapper shouty_){
shouty = shouty_;
}

@Given("Lucy is at {int}, {int}")
public void lucy_is_at(int xCoord, int yCoord) {
shouty.setLocation("Lucy", new Coordinate(xCoord, yCoord));
@Given("{word} is at {int}, {int}")
public void person_is_at(String person, int x, int y) {
shouty.setLocation(new PersonLocation(person, x, y));
}

@Given("Sean is at {int}, {int}")
public void sean_is_at(int xCoord, int yCoord) {
shouty.setLocation("Sean", new Coordinate(xCoord, yCoord));
@When("{word} shouts")
public void person_shouts(String person) {
shouty.shout(new Shout(person, "Hello, world"));
}

@When("Sean shouts")
public void sean_shouts() {
shouty.shout("Sean", ARBITRARY_MESSAGE);
@When("{word} shouts from {int}, {int}")
public void person_shouts(String person, int x, int y) {
shouty.shout(new Shout(person, "Hello, world", x, y));
}

@Then("Lucy should hear Sean")
public void lucy_should_hear_sean() {
assertEquals(1, shouty.getShoutsHeardBy("Lucy").size());
@Then("{word} should hear {word}")
public void listener_should_hear_shouter(String listener, String shouter) {
assertEquals(shouter, shouty.getShouts().get(0).person);
}

@Then("Lucy should hear nothing")
public void lucy_should_hear_nothing() {
assertEquals(emptyMap(), shouty.getShoutsHeardBy("Lucy"));
@Then("{word} should not hear {word}")
public void listener_should_not_hear_shouter(String listener, String shouter) {
assertEquals(0, shouty.getShouts().size());
}
}
23 changes: 0 additions & 23 deletions src/test/java/shouty/ShoutyTypes.java

This file was deleted.

29 changes: 29 additions & 0 deletions src/test/java/shouty/SmokeAndMirrors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package shouty;

import io.cucumber.java.Before;
import io.cucumber.java.Scenario;

import java.io.Console;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used


public class SmokeAndMirrors {
private final ShoutyServiceWrapper shouty;

public SmokeAndMirrors(ShoutyServiceWrapper shouty_){
shouty = shouty_;
}

@Before
public void setupExampleData(Scenario scenario) {
switch (scenario.getName()) {
case "In range shout is heard":
case "Range calculated using specified location of business shout":
shouty.chooseStubbedData("0");
break;
case "Out of range shout is not heard":
shouty.chooseStubbedData("1");
break;
default:
throw new RuntimeException("Unrecognised scenario name");
}
}
}
Loading