|
1 | 1 | package org.json.junit; |
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertEquals; |
3 | 4 | import static org.junit.Assert.assertSame; |
4 | 5 |
|
5 | 6 | import org.json.JSONObject; |
@@ -28,7 +29,7 @@ public void emptyPointer() { |
28 | 29 |
|
29 | 30 | @Test(expected = NullPointerException.class) |
30 | 31 | public void nullPointer() { |
31 | | - new JSONPointer(null); |
| 32 | + new JSONPointer((String) null); |
32 | 33 | } |
33 | 34 |
|
34 | 35 | @Test |
@@ -103,5 +104,39 @@ public void arrayIndexFailure() { |
103 | 104 | public void primitiveFailure() { |
104 | 105 | query("/obj/key/failure"); |
105 | 106 | } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void builderTest() { |
| 110 | + JSONPointer pointer = JSONPointer.builder() |
| 111 | + .append("obj") |
| 112 | + .append("other~key").append("another/key") |
| 113 | + .append(0) |
| 114 | + .build(); |
| 115 | + assertEquals("val", pointer.queryFrom(document)); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void toStringEscaping() { |
| 120 | + JSONPointer pointer = JSONPointer.builder() |
| 121 | + .append("obj") |
| 122 | + .append("other~key").append("another/key") |
| 123 | + .append("\"") |
| 124 | + .append(0) |
| 125 | + .build(); |
| 126 | + assertEquals("/obj/other~0key/another~1key/\\\"/0", pointer.toString()); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void emptyPointerToString() { |
| 131 | + assertEquals("", new JSONPointer("").toString()); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + public void toURIFragment() { |
| 136 | + assertEquals("#/c%25d", new JSONPointer("/c%d").toURIFragment()); |
| 137 | + assertEquals("#/e%5Ef", new JSONPointer("/e^f").toURIFragment()); |
| 138 | + assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment()); |
| 139 | + assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment()); |
| 140 | + } |
106 | 141 |
|
107 | 142 | } |
0 commit comments