1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

adding unittests for JSPONPointer#toString(), toURIFragment() and its builder class

This commit is contained in:
Bence Erős 2016-05-03 23:20:17 +02:00
parent e748c60eb1
commit 6edc093803
2 changed files with 42 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package org.json.junit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.json.JSONObject;
@ -28,7 +29,7 @@ public class JSONPointerTest {
@Test(expected = NullPointerException.class)
public void nullPointer() {
new JSONPointer(null);
new JSONPointer((String) null);
}
@Test
@ -104,4 +105,38 @@ public class JSONPointerTest {
query("/obj/key/failure");
}
@Test
public void builderTest() {
JSONPointer pointer = JSONPointer.builder()
.append("obj")
.append("other~key").append("another/key")
.append(0)
.build();
assertEquals("val", pointer.queryFrom(document));
}
@Test
public void toStringEscaping() {
JSONPointer pointer = JSONPointer.builder()
.append("obj")
.append("other~key").append("another/key")
.append("\"")
.append(0)
.build();
assertEquals("/obj/other~0key/another~1key/\\\"/0", pointer.toString());
}
@Test
public void emptyPointerToString() {
assertEquals("", new JSONPointer("").toString());
}
@Test
public void toURIFragment() {
assertEquals("#/c%25d", new JSONPointer("/c%d").toURIFragment());
assertEquals("#/e%5Ef", new JSONPointer("/e^f").toURIFragment());
assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment());
assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment());
}
}

View file

@ -14,6 +14,11 @@
" ": 7,
"m~n": 8,
"obj" : {
"key" : "value"
"key" : "value",
"other~key" : {
"another/key" : [
"val"
]
}
}
}