Skip to content

Commit 342ca1f

Browse files
author
Kim A. Betti
committed
Made Gauva a test dependency only
1 parent c0e9f77 commit 342ca1f

File tree

5 files changed

+19
-59
lines changed

5 files changed

+19
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ simple services to expose.
8888

8989
Roadmap 2.0
9090
-----------
91-
I would like to drop Guava and write it in Kotlin.
91+
Perhaps I'll write it in Kotlin.

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ jacocoTestReport {
5959
}
6060

6161
dependencies {
62-
implementation 'com.google.guava:guava:28.0-jre'
63-
62+
testImplementation 'com.google.guava:guava:28.0-jre'
6463
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
6564
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
6665
testImplementation 'org.assertj:assertj-core:3.13.2'

src/main/java/com/developerb/nmxmlp/NX.java

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

18-
import com.google.common.io.ByteSource;
1918
import org.w3c.dom.Document;
2019
import org.w3c.dom.DocumentType;
2120
import org.w3c.dom.Element;
@@ -97,22 +96,7 @@ public Cursor from(String xml) throws Ex {
9796
}
9897

9998
public Cursor from(final String xml, ReadContext context) throws Ex {
100-
return from(new ByteSource() {
101-
102-
@Override
103-
public InputStream openStream() {
104-
return new ByteArrayInputStream(xml.getBytes());
105-
}
106-
107-
}, context);
108-
}
109-
110-
public Cursor from(ByteSource source, ReadContext context) throws Ex {
111-
try {
112-
return from(source.openStream(), context);
113-
} catch (Exception ex) {
114-
throw new Ex("Failed to initialize xml cursor", ex);
115-
}
99+
return from(new ByteArrayInputStream(xml.getBytes()), context);
116100
}
117101

118102
public Cursor from(InputStream stream, ReadContext context) throws Ex {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.io.Resources;
2020
import org.junit.jupiter.api.BeforeEach;
2121

22+
import java.io.IOException;
2223
import java.net.URL;
2324

2425

@@ -36,6 +37,7 @@ protected void withNx(NX nx) {
3637
// A good place for tests to add extractors etc.
3738
}
3839

40+
@SuppressWarnings("UnstableApiUsage")
3941
protected NX.Cursor parseResource(String resourceName) {
4042
URL svgResource = Resources.getResource(resourceName);
4143
ByteSource svgByteSource = Resources.asByteSource(svgResource);
@@ -48,7 +50,11 @@ protected NX.Cursor parse(String xml) {
4850
}
4951

5052
protected NX.Cursor parse(ByteSource source) {
51-
return nx.from(source, new NX.ReadContext(null));
53+
try {
54+
return nx.from(source.openStream(), new NX.ReadContext(null));
55+
} catch (IOException ex) {
56+
throw new IllegalStateException(ex);
57+
}
5258
}
5359

5460
}

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

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.google.common.io.ByteSource;
1919
import org.junit.jupiter.api.Test;
2020

21-
import java.io.InputStream;
22-
2321
import static com.google.common.base.Charsets.UTF_8;
2422
import static org.assertj.core.api.Assertions.assertThat;
2523
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -34,11 +32,10 @@ void loadInvalidXML() {
3432
parse("<root><unclosedTag></root>");
3533

3634
fail("Should not have accepted invalid xml");
37-
}
38-
catch (NX.Ex ex) {
35+
} catch (NX.Ex ex) {
3936
assertThat(ex)
40-
.as("Expected exception")
41-
.hasMessage("Failed to initialize xml cursor");
37+
.as("Expected exception")
38+
.hasMessage("Failed to initialize xml cursor");
4239
}
4340
}
4441

@@ -48,23 +45,21 @@ void loadInvalidXMLFromBytes() {
4845
parse(ByteSource.wrap("<root><unclosedTag></root>".getBytes(UTF_8)));
4946

5047
fail("Should not have accepted invalid xml");
51-
}
52-
catch (NX.Ex ex) {
48+
} catch (NX.Ex ex) {
5349
assertThat(ex)
54-
.as("Expected exception")
55-
.hasMessage("Failed to initialize xml cursor");
50+
.as("Expected exception")
51+
.hasMessage("Failed to initialize xml cursor");
5652
}
5753
}
5854

5955
@Test
6056
void readingNodeWithDuplicateAttributeTriggersException() {
6157
try {
6258
parse("<people><person name='First' name='Second' /></people>");
63-
}
64-
catch (NX.Ex ex) {
59+
} catch (NX.Ex ex) {
6560
assertThat(ex.getCause().getCause())
66-
.as("Expected exception")
67-
.hasMessageContaining("Attribute \"name\" was already specified for element \"person\"");
61+
.as("Expected exception")
62+
.hasMessageContaining("Attribute \"name\" was already specified for element \"person\"");
6863
}
6964
}
7065

@@ -76,28 +71,4 @@ void loadValidXML() {
7671
assertEquals("root", cursor.name());
7772
}
7873

79-
@Test
80-
void failingToReadFromByteSource() {
81-
try {
82-
parse(new ByteSource() {
83-
84-
@Override
85-
public InputStream openStream() {
86-
throw new IllegalStateException("Oups...");
87-
}
88-
89-
});
90-
}
91-
catch (NX.Ex ex) {
92-
assertThat(ex)
93-
.as("Expected exception")
94-
.hasMessage("Failed to initialize xml cursor");
95-
96-
assertThat(ex.getCause())
97-
.as("Cause of the expected exception")
98-
.isInstanceOf(IllegalStateException.class)
99-
.hasMessage("Oups...");
100-
}
101-
}
102-
10374
}

0 commit comments

Comments
 (0)