From adb3118d31f84cd4d1b60828a95f64c0c9e282bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Er=C5=91s?= Date: Thu, 5 May 2016 16:00:15 +0200 Subject: [PATCH] added test for checking if the JSONPointer is immutable --- src/test/org/json/junit/JSONPointerTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/org/json/junit/JSONPointerTest.java b/src/test/org/json/junit/JSONPointerTest.java index f17ba6e..820023b 100644 --- a/src/test/org/json/junit/JSONPointerTest.java +++ b/src/test/org/json/junit/JSONPointerTest.java @@ -2,6 +2,7 @@ package org.json.junit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; import org.json.JSONObject; import org.json.JSONPointer; @@ -143,5 +144,16 @@ public class JSONPointerTest { assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment()); assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment()); } + + @Test + public void tokenListIsCopiedInConstructor() { + JSONPointer.Builder b = JSONPointer.builder().append("key1"); + JSONPointer jp1 = b.build(); + b.append("key2"); + JSONPointer jp2 = b.build(); + if(jp1.toString().equals(jp2.toString())) { + fail("Oops, my pointers are sharing a backing array"); + } + } }