Skip to content

Commit adb3118

Browse files
committed
added test for checking if the JSONPointer is immutable
1 parent 2eed4be commit adb3118

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/test/org/json/junit/JSONPointerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertSame;
5+
import static org.junit.Assert.fail;
56

67
import org.json.JSONObject;
78
import org.json.JSONPointer;
@@ -143,5 +144,16 @@ public void toURIFragment() {
143144
assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment());
144145
assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment());
145146
}
147+
148+
@Test
149+
public void tokenListIsCopiedInConstructor() {
150+
JSONPointer.Builder b = JSONPointer.builder().append("key1");
151+
JSONPointer jp1 = b.build();
152+
b.append("key2");
153+
JSONPointer jp2 = b.build();
154+
if(jp1.toString().equals(jp2.toString())) {
155+
fail("Oops, my pointers are sharing a backing array");
156+
}
157+
}
146158

147159
}

0 commit comments

Comments
 (0)