Skip to content

Commit 490954d

Browse files
committed
Try using shared test util classes
1 parent b57f440 commit 490954d

File tree

2 files changed

+20
-83
lines changed

2 files changed

+20
-83
lines changed

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,19 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
8787
</dependency>
8888

8989
<!-- Test dependencies -->
90-
90+
91+
<!-- 16-Jan-2025, tatu: Use the new (in 3.0) shared core test-jar
92+
for some shared test functionality.
93+
-->
94+
<dependency>
95+
<groupId>tools.jackson.core</groupId>
96+
<artifactId>jackson-core</artifactId>
97+
<version>${jackson.version.core}</version>
98+
<classifier>tests</classifier>
99+
<type>test-jar</type>
100+
<scope>test</scope>
101+
</dependency>
102+
91103
<!-- 11-Jan-2025, joohyukkim: For JSTEP-10, migrate to JUnit5 -->
92104
<dependency>
93105
<groupId>org.junit.jupiter</groupId>

src/test/java/tools/jackson/dataformat/xml/XmlTestUtil.java

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package tools.jackson.dataformat.xml;
22

33
import java.io.*;
4-
import java.nio.charset.StandardCharsets;
5-
import java.util.Arrays;
64

75
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
8-
import tools.jackson.core.*;
6+
7+
import tools.jackson.core.JsonParser;
8+
import tools.jackson.core.testutil.JacksonTestUtilBase;
9+
910
import tools.jackson.databind.AnnotationIntrospector;
11+
1012
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;
13+
1114
import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector;
1215

1316
import static org.junit.jupiter.api.Assertions.assertEquals;
1417
import static org.junit.jupiter.api.Assertions.fail;
1518

1619
public abstract class XmlTestUtil
20+
extends JacksonTestUtilBase
1721
{
1822
protected static final String DEFAULT_NEW_LINE;
1923

@@ -249,75 +253,19 @@ protected AnnotationIntrospector jakartaXMLBindAnnotationIntrospector() {
249253
/**********************************************************
250254
*/
251255

252-
protected void assertToken(JsonToken expToken, JsonToken actToken)
253-
{
254-
if (actToken != expToken) {
255-
fail("Expected token "+expToken+", current token "+actToken);
256-
}
257-
}
258-
259-
protected void assertToken(JsonToken expToken, JsonParser jp)
260-
{
261-
assertToken(expToken, jp.currentToken());
262-
}
263-
264-
/**
265-
* Method that gets textual contents of the current token using
266-
* available methods, and ensures results are consistent, before
267-
* returning them
268-
*/
269-
protected String getAndVerifyText(JsonParser jp)
270-
throws IOException
271-
{
272-
// Ok, let's verify other accessors
273-
int actLen = jp.getStringLength();
274-
char[] ch = jp.getStringCharacters();
275-
String str2 = new String(ch, jp.getStringOffset(), actLen);
276-
String str = jp.getString();
277-
278-
if (str.length() != actLen) {
279-
fail("Internal problem (jp.token == "+jp.currentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
280-
}
281-
assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same");
282-
283-
return str;
284-
}
285-
286256
protected void verifyFieldName(JsonParser jp, String expName)
287257
throws IOException
288258
{
289259
assertEquals(expName, jp.getString());
290260
assertEquals(expName, jp.currentName());
291261
}
292-
293-
protected void verifyException(Throwable e, String... matches)
294-
{
295-
String msg = e.getMessage();
296-
String lmsg = (msg == null) ? "" : msg.toLowerCase();
297-
for (String match : matches) {
298-
String lmatch = match.toLowerCase();
299-
if (lmsg.indexOf(lmatch) >= 0) {
300-
return;
301-
}
302-
}
303-
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one ("+
304-
e.getClass().getName()+") with message \""+msg+"\"");
305-
}
306262

307263
/*
308264
/**********************************************************
309265
/* Helper methods, other
310266
/**********************************************************
311267
*/
312268

313-
protected static String a2q(String content) {
314-
return content.replace("'", "\"");
315-
}
316-
317-
protected byte[] utf8Bytes(String str) {
318-
return str.getBytes(StandardCharsets.UTF_8);
319-
}
320-
321269
/**
322270
* Helper method that tries to remove unnecessary namespace
323271
* declaration that default JDK XML parser (SJSXP) sees fit
@@ -346,29 +294,6 @@ protected String readAll(File f) throws IOException
346294
return sb.toString();
347295
}
348296

349-
protected byte[] readResource(String ref)
350-
{
351-
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
352-
final byte[] buf = new byte[4000];
353-
354-
InputStream in = getClass().getResourceAsStream(ref);
355-
if (in != null) {
356-
try {
357-
int len;
358-
while ((len = in.read(buf)) > 0) {
359-
bytes.write(buf, 0, len);
360-
}
361-
in.close();
362-
} catch (IOException e) {
363-
throw new RuntimeException("Failed to read resource '"+ref+"': "+e);
364-
}
365-
}
366-
if (bytes.size() == 0) {
367-
throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?");
368-
}
369-
return bytes.toByteArray();
370-
}
371-
372297
public String jaxbSerialized(Object ob, Class<?>... classes) throws Exception
373298
{
374299
StringWriter sw = new StringWriter();

0 commit comments

Comments
 (0)