| 1 |
package com.fasterxml.jackson.jr.stree; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
|
| 5 |
import com.fasterxml.jackson.core.*; |
| 6 |
import com.fasterxml.jackson.jr.ob.JSON; |
| 7 |
|
| 8 |
import junit.framework.TestCase; |
| 9 |
|
| 10 |
public abstract class JacksonJrTreeTestBase extends TestCase |
| 11 |
{ |
| 12 |
protected final JsonFactory _factory = new JsonFactory(); |
| 13 |
|
| 14 |
protected void assertToken(JsonToken expToken, JsonToken actToken) |
| 15 |
{ |
| 16 |
if (actToken != expToken) { |
| 17 |
fail("Expected token "+expToken+", current token "+actToken); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
protected void assertToken(JsonToken expToken, JsonParser p) |
| 22 |
{ |
| 23 |
assertToken(expToken, p.currentToken()); |
| 24 |
} |
| 25 |
|
| 26 |
protected void verifyException(Throwable e, String... matches) |
| 27 |
{ |
| 28 |
String msg = e.getMessage(); |
| 29 |
String lmsg = (msg == null) ? "" : msg.toLowerCase(); |
| 30 |
for (String match : matches) { |
| 31 |
String lmatch = match.toLowerCase(); |
| 32 |
if (lmsg.indexOf(lmatch) >= 0) { |
| 33 |
return; |
| 34 |
} |
| 35 |
} |
| 36 |
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\""); |
| 37 |
} |
| 38 |
|
| 39 |
protected String q(String str) { |
| 40 |
return "\"" + str + "\""; |
| 41 |
} |
| 42 |
|
| 43 |
protected String a2q(String json) { |
| 44 |
return json.replace("'", "\""); |
| 45 |
} |
| 46 |
|
| 47 |
protected JSON jsonWithTreeCodec() { |
| 48 |
return JSON.builder() |
| 49 |
// 13-Feb-2020, tatu: There are 2 different ways actually.. |
| 50 |
// .treeCodec(new JacksonJrsTreeCodec()) |
| 51 |
.register(new JrSimpleTreeExtension()) |
| 52 |
.build(); |
| 53 |
} |
| 54 |
} |