Skip to content

Commit c3b73c5

Browse files
mogronalolpivovarit
authored andcommitted
Bael 627 (eugenp#1431)
* Initial commit * Spock examples * Changed Spock Version
1 parent 8e060b9 commit c3b73c5

114 files changed

Lines changed: 2967 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎groovy-spock/pom.xml‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.spockframework</groupId>
6+
<artifactId>groovy-spock</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<name>Spock Framework - Example Project</name>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.codehaus.gmavenplus</groupId>
20+
<artifactId>gmavenplus-plugin</artifactId>
21+
<version>1.5</version>
22+
<executions>
23+
<execution>
24+
<goals>
25+
<goal>compile</goal>
26+
<goal>testCompile</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.spockframework</groupId>
37+
<artifactId>spock-core</artifactId>
38+
<version>1.0-groovy-2.4</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.codehaus.groovy</groupId>
43+
<artifactId>groovy-all</artifactId>
44+
<version>2.4.7</version>
45+
</dependency>
46+
</dependencies>
47+
</project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import spock.lang.Specification
2+
3+
class FirstSpecification extends Specification {
4+
5+
def "one plus one should equal two"() {
6+
expect:
7+
1 + 1 == 2
8+
}
9+
10+
def "two plus two should equal four"() {
11+
given:
12+
int left = 2
13+
int right = 2
14+
15+
when:
16+
int result = left + right
17+
18+
then:
19+
result == 4
20+
}
21+
22+
def "Should be able to remove from list"() {
23+
given:
24+
def list = [1, 2, 3, 4]
25+
26+
when:
27+
list.remove(0)
28+
29+
then:
30+
list == [2, 3, 4]
31+
}
32+
33+
def "Should get an index out of bounds when removing a non-existent item"() {
34+
given:
35+
def list = [1, 2, 3, 4]
36+
37+
when:
38+
list.remove(20)
39+
40+
then:
41+
thrown(IndexOutOfBoundsException)
42+
list.size() == 4
43+
}
44+
45+
def "numbers to the power of two"(int a, int b, int c) {
46+
expect:
47+
Math.pow(a, b) == c
48+
49+
where:
50+
a | b | c
51+
1 | 2 | 1
52+
2 | 2 | 4
53+
3 | 2 | 9
54+
}
55+
56+
def "Should return default value for mock"() {
57+
given:
58+
def paymentGateway = Mock(PaymentGateway)
59+
60+
when:
61+
def result = paymentGateway.makePayment(12.99)
62+
63+
then:
64+
!result
65+
}
66+
67+
def "Should return true value for mock"() {
68+
given:
69+
def paymentGateway = Mock(PaymentGateway)
70+
paymentGateway.makePayment(20) >> true
71+
72+
when:
73+
def result = paymentGateway.makePayment(20)
74+
75+
then:
76+
result
77+
}
78+
79+
def "Should verify notify was called"() {
80+
given:
81+
def notifier = Mock(Notifier)
82+
83+
when:
84+
notifier.notify('foo')
85+
86+
then:
87+
1 * notifier.notify('foo')
88+
}
89+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Notifier {
2+
void notify(String message)
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface PaymentGateway {
2+
boolean makePayment(BigDecimal amount)
3+
}

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<!-- <module>gatling</module> --> <!-- not meant to run as part of the standard build -->
4444

4545

46+
<module>groovy-spock</module>
4647
<module>gson</module>
4748
<module>guava</module>
4849
<module>guava18</module>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
.settings/
3+
.classpath
4+
.project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
###The Course
2+
The "REST With Spring" Classes: http://bit.ly/restwithspring
3+
4+
###Relevant Articles:
5+
- [Quick Guide to @RestClientTest in Spring Boot](http://www.baeldung.com/restclienttest-in-spring-boot)
6+
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
7+
- [A Guide to Spring in Eclipse STS](http://www.baeldung.com/eclipse-sts-spring)
8+
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
9+
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
10+
- [The @ServletComponentScan Annotation in Spring Boot](http://www.baeldung.com/spring-servletcomponentscan)
11+
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
12+
- [Intro to Building an Application with Spring Boot](http://www.baeldung.com/intro-to-spring-boot)
13+
- [How to Register a Servlet in a Java Web Application](http://www.baeldung.com/register-servlet)

0 commit comments

Comments
 (0)