Group testing modules (#3014)
* move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict
This commit is contained in:
committed by
GitHub
parent
b383d83bf4
commit
776a01429e
3
testing-modules/groovy-spock/README.md
Normal file
3
testing-modules/groovy-spock/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Relevant articles
|
||||
|
||||
- [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock)
|
||||
54
testing-modules/groovy-spock/pom.xml
Normal file
54
testing-modules/groovy-spock/pom.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0"?>
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>groovy-spock</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spock Framework - Example Project</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>spock-core</artifactId>
|
||||
<version>1.0-groovy-2.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.4.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,89 @@
|
||||
import spock.lang.Specification
|
||||
|
||||
class FirstSpecification extends Specification {
|
||||
|
||||
def "one plus one should equal two"() {
|
||||
expect:
|
||||
1 + 1 == 2
|
||||
}
|
||||
|
||||
def "two plus two should equal four"() {
|
||||
given:
|
||||
int left = 2
|
||||
int right = 2
|
||||
|
||||
when:
|
||||
int result = left + right
|
||||
|
||||
then:
|
||||
result == 4
|
||||
}
|
||||
|
||||
def "Should be able to remove from list"() {
|
||||
given:
|
||||
def list = [1, 2, 3, 4]
|
||||
|
||||
when:
|
||||
list.remove(0)
|
||||
|
||||
then:
|
||||
list == [2, 3, 4]
|
||||
}
|
||||
|
||||
def "Should get an index out of bounds when removing a non-existent item"() {
|
||||
given:
|
||||
def list = [1, 2, 3, 4]
|
||||
|
||||
when:
|
||||
list.remove(20)
|
||||
|
||||
then:
|
||||
thrown(IndexOutOfBoundsException)
|
||||
list.size() == 4
|
||||
}
|
||||
|
||||
def "numbers to the power of two"(int a, int b, int c) {
|
||||
expect:
|
||||
Math.pow(a, b) == c
|
||||
|
||||
where:
|
||||
a | b | c
|
||||
1 | 2 | 1
|
||||
2 | 2 | 4
|
||||
3 | 2 | 9
|
||||
}
|
||||
|
||||
def "Should return default value for mock"() {
|
||||
given:
|
||||
def paymentGateway = Mock(PaymentGateway)
|
||||
|
||||
when:
|
||||
def result = paymentGateway.makePayment(12.99)
|
||||
|
||||
then:
|
||||
!result
|
||||
}
|
||||
|
||||
def "Should return true value for mock"() {
|
||||
given:
|
||||
def paymentGateway = Mock(PaymentGateway)
|
||||
paymentGateway.makePayment(20) >> true
|
||||
|
||||
when:
|
||||
def result = paymentGateway.makePayment(20)
|
||||
|
||||
then:
|
||||
result
|
||||
}
|
||||
|
||||
def "Should verify notify was called"() {
|
||||
given:
|
||||
def notifier = Mock(Notifier)
|
||||
|
||||
when:
|
||||
notifier.notify('foo')
|
||||
|
||||
then:
|
||||
1 * notifier.notify('foo')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
interface Notifier {
|
||||
void notify(String message)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
interface PaymentGateway {
|
||||
boolean makePayment(BigDecimal amount)
|
||||
}
|
||||
Reference in New Issue
Block a user