Skip to content

Commit a8bf430

Browse files
committed
Converted tests to JUnit 5
1 parent 9ccabda commit a8bf430

17 files changed

Lines changed: 149 additions & 131 deletions

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jacocoTestReport {
6262
dependencies {
6363
implementation 'com.google.guava:guava:28.0-jre'
6464

65-
testImplementation 'junit:junit:4.12'
65+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
66+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
6667
testImplementation 'org.assertj:assertj-core:3.13.2'
6768
}
6869

@@ -76,6 +77,10 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
7677
from javadoc.destinationDir
7778
}
7879

80+
test {
81+
useJUnitPlatform()
82+
}
83+
7984
artifacts {
8085
archives sourcesJar, javadocJar
8186
}

src/test/java/com/developerb/nmxmlp/AbstractNXTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import com.google.common.io.ByteSource;
1919
import com.google.common.io.Resources;
20-
import org.junit.Before;
20+
import org.junit.jupiter.api.BeforeEach;
2121

2222
import java.net.URL;
2323

@@ -26,7 +26,7 @@ public abstract class AbstractNXTest {
2626

2727
private NX nx;
2828

29-
@Before
29+
@BeforeEach
3030
public final void initialize() {
3131
this.nx = new NX();
3232
withNx(nx);

src/test/java/com/developerb/nmxmlp/AttributeTest.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,26 @@
1515
*/
1616
package com.developerb.nmxmlp;
1717

18-
import org.junit.Test;
18+
19+
import org.junit.jupiter.api.Test;
1920

2021
import java.nio.charset.StandardCharsets;
2122

2223
import static org.assertj.core.api.Assertions.assertThat;
23-
import static org.junit.Assert.*;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.fail;
2429

2530

26-
public class AttributeTest extends AbstractNXTest {
31+
class AttributeTest extends AbstractNXTest {
2732

2833
private final String xml = "<root><person firstName='Nasse' lastName='Nøff' age='10' /></root>";
2934

3035

3136
@Test
32-
public void removeAttribute() {
37+
void removeAttribute() {
3338
NX.Cursor root = parse(xml);
3439
NX.Cursor person = root.to("person");
3540

@@ -41,7 +46,7 @@ public void removeAttribute() {
4146
}
4247

4348
@Test
44-
public void hasAttr() {
49+
void hasAttr() {
4550
NX.Cursor root = parse(xml);
4651
NX.Cursor person = root.to("person");
4752

@@ -51,7 +56,7 @@ public void hasAttr() {
5156
}
5257

5358
@Test
54-
public void readingAttributeAsText() {
59+
void readingAttributeAsText() {
5560
NX.Cursor root = parse(xml);
5661
NX.Cursor person = root.to("person");
5762

@@ -60,7 +65,7 @@ public void readingAttributeAsText() {
6065
}
6166

6267
@Test
63-
public void attemptingToGetMissingAttributeShouldThrowException() {
68+
void attemptingToGetMissingAttributeShouldThrowException() {
6469
NX.Cursor root = parse(xml);
6570
NX.Cursor person = root.to("person");
6671

@@ -76,7 +81,7 @@ public void attemptingToGetMissingAttributeShouldThrowException() {
7681
}
7782

7883
@Test
79-
public void textContentOfMissingAttributeShouldBeNull() {
84+
void textContentOfMissingAttributeShouldBeNull() {
8085
NX.Cursor root = parse(xml);
8186
NX.Cursor person = root.to("person");
8287

@@ -85,7 +90,7 @@ public void textContentOfMissingAttributeShouldBeNull() {
8590
}
8691

8792
@Test
88-
public void updatingTextOfMissingAttributeShouldDoNothing() {
93+
void updatingTextOfMissingAttributeShouldDoNothing() {
8994
NX.Cursor root = parse(xml);
9095
NX.Cursor person = root.to("person");
9196

@@ -94,7 +99,7 @@ public void updatingTextOfMissingAttributeShouldDoNothing() {
9499
}
95100

96101
@Test
97-
public void mapAttributeTextUsingFunction() {
102+
void mapAttributeTextUsingFunction() {
98103
NX.Cursor root = parse(xml);
99104
NX.Cursor person = root.to("person");
100105

@@ -106,7 +111,7 @@ public void mapAttributeTextUsingFunction() {
106111
}
107112

108113
@Test
109-
public void mapAttributeTextUsingMethodReference() {
114+
void mapAttributeTextUsingMethodReference() {
110115
NX.Cursor root = parse(xml);
111116
NX.Cursor person = root.to("person");
112117

@@ -118,7 +123,7 @@ public void mapAttributeTextUsingMethodReference() {
118123
}
119124

120125
@Test
121-
public void mapMissingOptionalAttributeReturnsNull() {
126+
void mapMissingOptionalAttributeReturnsNull() {
122127
NX.Cursor root = parse(xml);
123128
NX.Cursor person = root.to("person");
124129

src/test/java/com/developerb/nmxmlp/DataExtractionTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
package com.developerb.nmxmlp;
1717

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

2020
import java.util.List;
2121

2222
import static org.assertj.core.api.Assertions.assertThat;
23-
import static org.junit.Assert.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
2424

25-
public class DataExtractionTest extends AbstractNXTest {
25+
class DataExtractionTest extends AbstractNXTest {
2626

2727
private final String peopleXml = "<people>" +
2828
"<person><name>Nasse Nøff</name><age>5</age></person>" +
@@ -36,31 +36,31 @@ public class DataExtractionTest extends AbstractNXTest {
3636

3737

3838
@Test
39-
public void simpleDataExtraction() throws Exception {
39+
void simpleDataExtraction() {
4040
NX.Cursor person = parse(personXml);
4141

4242
assertEquals("Nasse Nøff", person.to("name").text());
4343
assertEquals(5, (int) person.to("age").extract(Integer.class));
4444
}
4545

4646
@Test
47-
public void extractDouble() throws Exception {
47+
void extractDouble() {
4848
NX.Cursor root = parse("<root><double>3.14159265</double></root>");
4949
Double extracted = root.to("double").extract(Double.class);
5050

5151
assertEquals(extracted, extracted, 0.00001);
5252
}
5353

5454
@Test
55-
public void extractFloat() throws Exception {
55+
void extractFloat() {
5656
NX.Cursor root = parse("<root><float>3.14159265</float></root>");
5757
Float extracted = root.to("float").extract(Float.class);
5858

5959
assertEquals(extracted, extracted, 0.00001);
6060
}
6161

6262
@Test
63-
public void extractLong() throws Exception {
63+
void extractLong() {
6464
NX.Cursor root = parse("<root><long>314159265</long></root>");
6565
Long extracted = root.to("long").extract(Long.class);
6666

@@ -70,14 +70,14 @@ public void extractLong() throws Exception {
7070
}
7171

7272
@Test
73-
public void countElements() throws Exception {
73+
void countElements() {
7474
NX.Cursor people = parse(peopleXml);
7575

7676
assertEquals(2, people.count("person"));
7777
}
7878

7979
@Test
80-
public void extractSingleObject() throws Exception {
80+
void extractSingleObject() {
8181
NX.Cursor person = parse(personXml);
8282

8383
NX.Extractor<Person> extractor = new PersonExtractor();
@@ -88,7 +88,7 @@ public void extractSingleObject() throws Exception {
8888
}
8989

9090
@Test
91-
public void extractObjectCollection() throws Exception {
91+
void extractObjectCollection() {
9292
NX.Cursor person = parse(peopleXml);
9393

9494
NX.Extractor<Person> extractor = new PersonExtractor();
@@ -105,8 +105,8 @@ public void extractObjectCollection() throws Exception {
105105

106106
static class Person {
107107

108-
public final String name;
109-
public final int age;
108+
final String name;
109+
final int age;
110110

111111
Person(String name, int age) {
112112
this.name = name;

src/test/java/com/developerb/nmxmlp/DataInsertTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
*/
1616
package com.developerb.nmxmlp;
1717

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

2020
import java.util.Arrays;
2121
import java.util.List;
2222

2323
import static java.nio.charset.StandardCharsets.UTF_8;
2424
import static org.assertj.core.api.Assertions.assertThat;
25-
import static org.junit.Assert.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
2626

27-
public class DataInsertTest extends AbstractNXTest {
27+
class DataInsertTest extends AbstractNXTest {
2828

2929
@Test
30-
public void insertCollectionNoNamespaces() throws NX.Ex {
30+
void insertCollectionNoNamespaces() throws NX.Ex {
3131
NX.Cursor peopleCursor = parse("<people><person name='Prototype' /></people>");
3232

3333
List<Person> people = Arrays.asList (
@@ -45,7 +45,7 @@ public void insertCollectionNoNamespaces() throws NX.Ex {
4545
}
4646

4747
@Test
48-
public void insertNamespacedSvg() throws NX.Ex {
48+
void insertNamespacedSvg() throws NX.Ex {
4949
NX.Cursor cursor = parseResource("svg/simple-svg.xhtml");
5050
NX.Cursor svg = cursor.to("body").to("svg");
5151

@@ -65,7 +65,7 @@ public void insertNamespacedSvg() throws NX.Ex {
6565
}
6666

6767
@Test
68-
public void updateSingleNodeTreeFromObject() throws Exception {
68+
void updateSingleNodeTreeFromObject() throws Exception {
6969
NX.Cursor soapEnvelope = parseResource("soap/soap-request.xml");
7070

7171
NX.Cursor requestHeader = soapEnvelope.to("header", "requestHeader");
@@ -79,7 +79,7 @@ public void updateSingleNodeTreeFromObject() throws Exception {
7979

8080

8181
@Test
82-
public void insertedElementsInConnectionShouldBePositionedInTheSamePlaceAsThePrototypeElement() throws NX.Ex {
82+
void insertedElementsInConnectionShouldBePositionedInTheSamePlaceAsThePrototypeElement() throws NX.Ex {
8383
NX.Cursor root = parse("<root><repeatMe /><fixed>should-not-move</fixed></root>");
8484

8585
root.insertCollection("repeatMe", Arrays.asList("hei", "på", "deg"), NX.Cursor::text);
@@ -90,7 +90,7 @@ public void insertedElementsInConnectionShouldBePositionedInTheSamePlaceAsThePro
9090
}
9191

9292
@Test
93-
public void insertCollectionMissingPrototypeNode() {
93+
void insertCollectionMissingPrototypeNode() {
9494
NX.Cursor peopleCursor = parse("<people><person name='Prototype' /></people>");
9595
Iterable<String> pirates = Arrays.asList("Sabeltann", "Sortebill");
9696

src/test/java/com/developerb/nmxmlp/DumpXmlTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,38 @@
1515
*/
1616
package com.developerb.nmxmlp;
1717

18-
import org.junit.Test;
18+
19+
import org.junit.jupiter.api.Test;
1920

2021
import static com.developerb.nmxmlp.NX.Feature.DUMP_INDENTED_XML;
2122
import static com.developerb.nmxmlp.NX.Feature.DUMP_WITHOUT_XML_DECLARATION;
2223
import static java.nio.charset.StandardCharsets.ISO_8859_1;
2324
import static java.nio.charset.StandardCharsets.UTF_8;
2425
import static org.assertj.core.api.Assertions.assertThat;
25-
import static org.junit.Assert.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2627

27-
public class DumpXmlTest extends AbstractNXTest {
28+
class DumpXmlTest extends AbstractNXTest {
2829

2930
private String xml = "<a><b><c>value</c></b></a>";
3031

3132
@Test
32-
public void dumpXmlWithoutXmlDeclaration() {
33+
void dumpXmlWithoutXmlDeclaration() {
3334
NX nx = new NX();
3435
NX.Cursor root = nx.from(xml);
3536

3637
assertEquals("<a><b><c>value</c></b></a>", root.dumpXml(UTF_8, DUMP_WITHOUT_XML_DECLARATION));
3738
}
3839

3940
@Test
40-
public void dumpXmlFromChildNode() {
41+
void dumpXmlFromChildNode() {
4142
NX nx = new NX();
4243
NX.Cursor root = nx.from(xml);
4344

4445
assertEquals("<b><c>value</c></b>", root.to("b").dumpXml(UTF_8, DUMP_WITHOUT_XML_DECLARATION));
4546
}
4647

4748
@Test
48-
public void dumpIndentedXml() {
49+
void dumpIndentedXml() {
4950
NX nx = new NX();
5051
NX.Cursor root = nx.from(xml);
5152

@@ -57,14 +58,14 @@ public void dumpIndentedXml() {
5758
}
5859

5960
@Test
60-
public void dumpXmlWithXmlDeclaration() {
61+
void dumpXmlWithXmlDeclaration() {
6162
NX.Cursor root = parse(xml);
6263

6364
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b><c>value</c></b></a>", root.dumpXml(UTF_8));
6465
}
6566

6667
@Test
67-
public void dumpXmlLatin1() {
68+
void dumpXmlLatin1() {
6869
NX.Cursor root = parse(xml);
6970

7071
String utf8 = root.dumpXml(UTF_8);

src/test/java/com/developerb/nmxmlp/ErrorHandlingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
*/
1616
package com.developerb.nmxmlp;
1717

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121

2222

23-
public class ErrorHandlingTest extends AbstractNXTest {
23+
class ErrorHandlingTest extends AbstractNXTest {
2424

2525
private final String xml = "<root><person firstName='Nasse' lastName='Nøff' age='10' /></root>";
2626

2727
@Test
28-
public void attemptToNavigateToMissingNodeResultsInExceptionWithHelpfulMessage() {
28+
void attemptToNavigateToMissingNodeResultsInExceptionWithHelpfulMessage() {
2929
NX.Cursor cursor = parse(xml);
3030

3131
try {

0 commit comments

Comments
 (0)