| 
1 | 1 | package tools.jackson.dataformat.xml;  | 
2 | 2 | 
 
  | 
3 | 3 | import java.io.*;  | 
4 |  | -import java.nio.charset.StandardCharsets;  | 
5 |  | -import java.util.Arrays;  | 
6 | 4 | 
 
  | 
7 | 5 | 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 | + | 
9 | 10 | import tools.jackson.databind.AnnotationIntrospector;  | 
 | 11 | + | 
10 | 12 | import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;  | 
 | 13 | + | 
11 | 14 | import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector;  | 
12 | 15 | 
 
  | 
13 | 16 | import static org.junit.jupiter.api.Assertions.assertEquals;  | 
14 | 17 | import static org.junit.jupiter.api.Assertions.fail;  | 
15 | 18 | 
 
  | 
16 | 19 | public abstract class XmlTestUtil  | 
 | 20 | +    extends JacksonTestUtilBase  | 
17 | 21 | {  | 
18 | 22 |     protected static final String DEFAULT_NEW_LINE;  | 
19 | 23 | 
 
  | 
@@ -249,75 +253,19 @@ protected AnnotationIntrospector jakartaXMLBindAnnotationIntrospector() {  | 
249 | 253 |     /**********************************************************  | 
250 | 254 |      */  | 
251 | 255 | 
 
  | 
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 |  | - | 
286 | 256 |     protected void verifyFieldName(JsonParser jp, String expName)  | 
287 | 257 |         throws IOException  | 
288 | 258 |     {  | 
289 | 259 |         assertEquals(expName, jp.getString());  | 
290 | 260 |         assertEquals(expName, jp.currentName());  | 
291 | 261 |     }  | 
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 |  | -    }  | 
306 | 262 | 
 
  | 
307 | 263 |     /*  | 
308 | 264 |     /**********************************************************  | 
309 | 265 |     /* Helper methods, other  | 
310 | 266 |     /**********************************************************  | 
311 | 267 |      */  | 
312 | 268 | 
 
  | 
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 |  | -      | 
321 | 269 |     /**  | 
322 | 270 |      * Helper method that tries to remove unnecessary namespace  | 
323 | 271 |      * declaration that default JDK XML parser (SJSXP) sees fit  | 
@@ -346,29 +294,6 @@ protected String readAll(File f) throws IOException  | 
346 | 294 |         return sb.toString();  | 
347 | 295 |     }  | 
348 | 296 | 
 
  | 
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 |  | - | 
372 | 297 |     public String jaxbSerialized(Object ob, Class<?>... classes) throws Exception  | 
373 | 298 |     {  | 
374 | 299 |         StringWriter sw = new StringWriter();  | 
 | 
0 commit comments