Skip to content

Commit f18c993

Browse files
juarezjaramilloKevinGilmore
authored andcommitted
BAEL-918 Testing with JGoTesting (eugenp#1998)
1 parent b00ec6a commit f18c993

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎testing/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
<version>${jUnitParams.version}</version>
7171
<scope>test</scope>
7272
</dependency>
73+
<dependency>
74+
<groupId>org.jgotesting</groupId>
75+
<artifactId>jgotesting</artifactId>
76+
<version>${jgotesting.version}</version>
77+
<scope>test</scope>
78+
</dependency>
7379
</dependencies>
7480
<build>
7581
<plugins>
@@ -137,5 +143,6 @@
137143
<assertj-core.version>3.6.1</assertj-core.version>
138144
<truth.version>0.32</truth.version>
139145
<jUnitParams.version>1.1.0</jUnitParams.version>
146+
<jgotesting.version>0.12</jgotesting.version>
140147
</properties>
141148
</project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.baeldung.testing.jgotesting;
2+
3+
import java.io.File;
4+
import static org.hamcrest.Matchers.equalToIgnoringCase;
5+
import static org.hamcrest.Matchers.is;
6+
import org.jgotesting.rule.JGoTestRule;
7+
import static org.jgotesting.Assert.*; // same methods as org.junit.Assert.*
8+
import static org.jgotesting.Check.*; // ditto, with different names
9+
import static org.jgotesting.Testing.*;
10+
import org.jgotesting.Checker;
11+
import org.junit.Ignore;
12+
import org.junit.Rule;
13+
import org.junit.Test;
14+
15+
public class JGoTestingUnitTest {
16+
@Rule
17+
public final JGoTestRule test = new JGoTestRule();
18+
19+
@Test
20+
public void whenComparingIntegers_thenEqual() {
21+
int anInt = 10;
22+
23+
assertEquals(anInt, 10);
24+
checkEquals(anInt, 10);
25+
}
26+
27+
@Ignore
28+
@Test
29+
public void whenComparingNumbers_thenLoggedMessage() {
30+
log("There was something wrong when comparing numbers");
31+
32+
int anInt = 10;
33+
int anotherInt = 10;
34+
35+
checkEquals(anInt, 10);
36+
checkTrue("First number should be bigger", 10 > anotherInt);
37+
checkSame(anInt, anotherInt);
38+
}
39+
40+
@Ignore
41+
@Test
42+
public void whenComparingNumbers_thenFormattedMessage() {
43+
int anInt = 10;
44+
int anotherInt = 10;
45+
46+
logf("There was something wrong when comparing numbers %d and %d", anInt, anotherInt);
47+
48+
checkEquals(anInt, 10);
49+
checkTrue("First number should be bigger", 10 > anotherInt);
50+
checkSame(anInt, anotherInt);
51+
}
52+
53+
@Test
54+
public void whenComparingStrings_thenMultipleAssertions() {
55+
String aString = "This is a string";
56+
String anotherString = "This Is A String";
57+
58+
test.check(aString, equalToIgnoringCase(anotherString))
59+
.check(aString.length() == 16)
60+
.check(aString.startsWith("This"));
61+
}
62+
63+
@Ignore
64+
@Test
65+
public void whenComparingStrings_thenMultipleFailingAssertions() {
66+
String aString = "the test string";
67+
String anotherString = "The Test String";
68+
69+
checkEquals("Strings are not equal!", aString, anotherString);
70+
checkTrue("String is longer than one character", aString.length() == 1);
71+
checkSame("Strings are not the same", aString, anotherString);
72+
}
73+
74+
@Ignore
75+
@Test
76+
public void givenFile_whenDoesnotExists_thenTerminated() throws Exception {
77+
File aFile = new File("a_dummy_file.txt");
78+
terminateIf(aFile.exists(), is(false));
79+
80+
// This doesn't get executed
81+
checkEquals(aFile.getName(), "a_dummy_file.txt");
82+
}
83+
84+
@Test
85+
public void givenChecker_whenComparingStrings_thenEqual() throws Exception {
86+
Checker<String> aChecker = s -> s.matches("\\d+");
87+
88+
String aString = "1235";
89+
test.check(aString, aChecker);
90+
}
91+
92+
}
93+

0 commit comments

Comments
 (0)