Skip to content

Commit b31308d

Browse files
authored
Merge pull request #16 from Laffini/BDD
BDD
2 parents a12ab98 + 8ee9aaa commit b31308d

File tree

5 files changed

+132
-7
lines changed

5 files changed

+132
-7
lines changed

pom.xml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,48 @@
1111
</parent>
1212
<groupId>net.laffyco</groupId>
1313
<artifactId>java-matching-engine</artifactId>
14-
<version>0.0.1-SNAPSHOT</version>
14+
<version>0.1.0</version>
1515
<name>java-matching-engine</name>
1616
<description>A matching engine made in Java</description>
1717
<properties>
1818
<java.version>1.8</java.version>
1919
</properties>
2020
<dependencies>
21+
22+
<!-- Third party -->
2123
<dependency>
2224
<groupId>org.springframework.boot</groupId>
2325
<artifactId>spring-boot-starter-web</artifactId>
2426
</dependency>
25-
2627
<dependency>
2728
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-test</artifactId>
29-
<scope>test</scope>
29+
<artifactId>spring-boot-devtools</artifactId>
30+
<scope>runtime</scope>
3031
</dependency>
3132

33+
<!-- Test -->
34+
<dependency>
35+
<groupId>io.cucumber</groupId>
36+
<artifactId>cucumber-java</artifactId>
37+
<version>7.0.0</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.cucumber</groupId>
41+
<artifactId>cucumber-junit</artifactId>
42+
<version>7.0.0</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.junit.vintage</groupId>
47+
<artifactId>junit-vintage-engine</artifactId>
48+
<version>5.8.1</version>
49+
<scope>test</scope>
50+
</dependency>
3251
<dependency>
3352
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-devtools</artifactId>
35-
<scope>runtime</scope>
53+
<artifactId>spring-boot-starter-test</artifactId>
54+
<scope>test</scope>
3655
</dependency>
37-
3856
</dependencies>
3957

4058
<build>
@@ -43,7 +61,27 @@
4361
<groupId>org.springframework.boot</groupId>
4462
<artifactId>spring-boot-maven-plugin</artifactId>
4563
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
</plugin>
4668
</plugins>
69+
<pluginManagement>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>3.0.0-M5</version>
75+
<configuration>
76+
<includes>
77+
*
78+
</includes>
79+
<parallel>methods</parallel>
80+
<threadCount>10</threadCount>
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</pluginManagement>
4785
</build>
4886

4987
<distributionManagement>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.laffyco.javamatchingengine.scenarios;
2+
3+
import io.cucumber.junit.Cucumber;
4+
import io.cucumber.junit.CucumberOptions;
5+
import org.junit.runner.RunWith;
6+
7+
import static io.cucumber.junit.CucumberOptions.SnippetType.CAMELCASE;
8+
9+
/**
10+
* Cucumber test runner.
11+
*
12+
* @author Laffini
13+
*/
14+
@RunWith(Cucumber.class)
15+
@CucumberOptions(plugin = {"pretty", "summary"}, snippets = CAMELCASE,
16+
features = "src/test/java/net/laffyco/javamatchingengine/scenarios/")
17+
public class CucumberRunner {
18+
// Intentionally left blank.
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: Orders
2+
3+
Tests related to orders.
4+
5+
Scenario: Adding an order
6+
Given There is an instance of the order book
7+
When I add an order
8+
Then It is added to the order book
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package net.laffyco.javamatchingengine.scenarios.orders;
2+
3+
import io.cucumber.java.en.Given;
4+
import io.cucumber.java.en.Then;
5+
import io.cucumber.java.en.When;
6+
import net.laffyco.javamatchingengine.engine.Order;
7+
import net.laffyco.javamatchingengine.engine.OrderBook;
8+
import net.laffyco.javamatchingengine.engine.Side;
9+
10+
import java.util.List;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
/**
16+
* Orders feature steps.
17+
* @author Laffini
18+
*/
19+
public class OrdersSteps {
20+
21+
/**
22+
* Order book instance.
23+
*/
24+
private OrderBook orderBook;
25+
26+
/**
27+
* Order to add to order book.
28+
*/
29+
private Order order;
30+
31+
@Given("There is an instance of the order book")
32+
public void createOrderBook() {
33+
this.orderBook = new OrderBook();
34+
}
35+
36+
@When("I add an order")
37+
public void addOrder() {
38+
final double amount = 10;
39+
final double price = 25.59;
40+
final Side side = Side.BUY;
41+
42+
this.order = new Order(amount, price, side);
43+
this.orderBook.process(order);
44+
}
45+
46+
@Then("It is added to the order book")
47+
public void orderIsAdded() {
48+
final List<Order> buyOrders = this.orderBook.getBuyOrders();
49+
50+
// Assert there is only one order.
51+
final int oneOrder = 1;
52+
assertEquals(oneOrder, buyOrders.size());
53+
assertTrue(this.orderBook.getSellOrders().isEmpty());
54+
55+
// Assert orders are equal match.
56+
final Order addedOrder = buyOrders.get(0);
57+
assertEquals(this.order, addedOrder);
58+
}
59+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cucumber.publish.quiet=true

0 commit comments

Comments
 (0)