Debian Codegraph @

jr-annotation-support/src/test/java/com/fasterxml/jackson/jr/annotationsupport/ASTestBase.java

raw
1 package com.fasterxml.jackson.jr.annotationsupport;
2
3 import java.util.Arrays;
4
5 import com.fasterxml.jackson.annotation.JsonCreator;
6 import com.fasterxml.jackson.annotation.JsonProperty;
7 import com.fasterxml.jackson.annotation.JsonValue;
8 import com.fasterxml.jackson.jr.ob.JSON;
9
10 import junit.framework.TestCase;
11
12 public abstract class ASTestBase extends TestCase
13 {
14 protected static class NameBean {
15 protected String first, last;
16
17 public NameBean() { }
18 public NameBean(String f, String l) {
19 first = f;
20 last = l;
21 }
22
23 public String getFirst() { return first; }
24 public String getLast() { return last; }
25
26 public void setFirst(String n) { first = n; }
27 public void setLast(String n) { last = n; }
28 }
29
30 protected void verifyException(Throwable e, String... matches)
31 {
32 String msg = e.getMessage();
33 String lmsg = (msg == null) ? "" : msg.toLowerCase();
34 for (String match : matches) {
35 String lmatch = match.toLowerCase();
36 if (lmsg.indexOf(lmatch) >= 0) {
37 return;
38 }
39 }
40 fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
41 }
42
43 protected JSON jsonWithAnnotationSupport() {
44 return JSON.builder().register(JacksonAnnotationExtension.std).build();
45 }
46
47 /*
48 protected JsonParser parserFor(String source) throws IOException {
49 return parserFor(JSON.std, source);
50 }
51
52 protected JsonParser parserFor(JSON json, String source) throws IOException {
53 return json.getStreamingFactory().createParser(source.toCharArray());
54 }
55 */
56
57 protected String quote(String str) {
58 return "\"" + str + "\"";
59 }
60
61 protected String a2q(String json) {
62 return json.replace("'", "\"");
63 }
64 }