Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2021-02-26 22:47:42 +0000
committerThomas Wolf2021-03-09 13:10:08 +0000
commitd3fba63080073e57e76c8699c357bbce5dbea526 (patch)
tree2551da94e30c0d05f83f28c6af25eefabb77a82d
parenta911bafc6cd2a3983c6eb0d9f91655816aba67fd (diff)
downloadeclipse.platform.ua-d3fba63080073e57e76c8699c357bbce5dbea526.tar.gz
eclipse.platform.ua-d3fba63080073e57e76c8699c357bbce5dbea526.tar.xz
eclipse.platform.ua-d3fba63080073e57e76c8699c357bbce5dbea526.zip
Remove Util.getJson(String)
This method was used only in a test. Remove it, and replace its uses in the test by JsonParser.parseString() directly. Since the test strings are all known to be objects, casting to JsonObject is fine. Change-Id: If2c05cea20ec03f188fc76f143f5f66bbb76e133 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.tips.json/src/org/eclipse/tips/json/internal/Util.java22
-rw-r--r--org.eclipse.tips.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java16
3 files changed, 11 insertions, 29 deletions
diff --git a/org.eclipse.tips.json/src/org/eclipse/tips/json/internal/Util.java b/org.eclipse.tips.json/src/org/eclipse/tips/json/internal/Util.java
index a4dda393b..d146dd101 100644
--- a/org.eclipse.tips.json/src/org/eclipse/tips/json/internal/Util.java
+++ b/org.eclipse.tips.json/src/org/eclipse/tips/json/internal/Util.java
@@ -13,10 +13,7 @@
*******************************************************************************/
package org.eclipse.tips.json.internal;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.MessageFormat;
@@ -28,7 +25,6 @@ import org.osgi.framework.FrameworkUtil;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
public class Util {
@@ -127,24 +123,6 @@ public class Util {
}
/**
- * @param input the json string representation
- * @return the parsed json object or null if a json object could not be found in
- * the string
- * @throws IOException
- */
- public static JsonObject getJson(String input) throws IOException {
- try (InputStream stream = new ByteArrayInputStream(input.getBytes());
- InputStreamReader reader = new InputStreamReader(stream)) {
- JsonElement element = JsonParser.parseReader(reader);
- if (element instanceof JsonObject) {
- return (JsonObject) element;
- } else {
- return null;
- }
- }
- }
-
- /**
* Checks if the URL is valid.
*
* @param pUrl
diff --git a/org.eclipse.tips.tests/META-INF/MANIFEST.MF b/org.eclipse.tips.tests/META-INF/MANIFEST.MF
index 215691043..795c0144c 100644
--- a/org.eclipse.tips.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.tips.tests/META-INF/MANIFEST.MF
@@ -15,4 +15,4 @@ Require-Bundle: org.junit;bundle-version="4.12.0",
org.eclipse.tips.ui;bundle-version="0.1.0",
org.eclipse.tips.json;bundle-version="0.1.0"
Automatic-Module-Name: org.eclipse.tips.tests
-Import-Package: com.google.gson
+Import-Package: com.google.gson;version="[2.8.6,3.0.0)"
diff --git a/org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java b/org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java
index 7e16c41a6..b5d5865a4 100644
--- a/org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java
+++ b/org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java
@@ -7,6 +7,7 @@ import java.io.IOException;
import org.junit.Test;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
public class UtilTest {
@@ -14,7 +15,7 @@ public class UtilTest {
@Test
public void testGetValueOrDefaultJsonObjectStringString() throws IOException {
String jsonString = "{\"first\": \"Wim\", \"last\": \"Jongman\", \"variables\": {\"title\": \"Mr.\", \"age\": 53}}";
- JsonObject jsonObject = Util.getJson(jsonString);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
assertTrue(Util.getValueOrDefault(jsonObject, "first", "Mark").equals("Wim"));
assertTrue(Util.getValueOrDefault(jsonObject, "fake", "Mark").equals("Mark"));
}
@@ -23,7 +24,7 @@ public class UtilTest {
@Test
public void testGetValueOrDefaultJsonObjectStringInt() throws IOException {
String jsonString = "{\"age\": \"53\", \"last\": \"Jongman\"}";
- JsonObject jsonObject = Util.getJson(jsonString);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
assertTrue(Util.getValueOrDefault(jsonObject, "age", 100) == 53);
assertTrue(Util.getValueOrDefault(jsonObject, "fake", 101) == 101);
}
@@ -32,7 +33,7 @@ public class UtilTest {
@Test
public void testGetValueOrDefaultJsonObjectStringDouble() throws IOException {
String jsonString = "{\"double\": 5.21, \"last\": \"Jongman\"}";
- JsonObject jsonObject = Util.getJson(jsonString);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
assertTrue(Util.getValueOrDefault(jsonObject, "double", 10.10) == 5.21);
assertTrue(Util.getValueOrDefault(jsonObject, "fake", 101.6) == 101.6);
}
@@ -43,7 +44,8 @@ public class UtilTest {
String input = "${title} ${first} ${last} is ${age} years old.";
String result = "Mr. Wim Jongman is 53 years old.";
String jsonString = "{\"first\": \"Wim\", \"last\": \"Jongman\", \"variables\": {\"title\": \"Mr.\", \"age\": 53}}";
- String replace = Util.replace(Util.getJson(jsonString), input);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
+ String replace = Util.replace(jsonObject, input);
assertTrue(replace, replace.equals(result));
}
@@ -53,7 +55,8 @@ public class UtilTest {
String input = "${title} ${first} ${last} ${ddd} is ${age} years old.${title}";
String result = "Mr. Wim Jongman ${ddd} is 53 years old.Mr.";
String jsonString = "{\"first\": \"Wim\", \"last\": \"Jongman\", \"variables\": {\"title\": \"Mr.\", \"age\": 53}}";
- String replace = Util.replace(Util.getJson(jsonString), input);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
+ String replace = Util.replace(jsonObject, input);
assertTrue(replace, replace.equals(result));
}
@@ -63,7 +66,8 @@ public class UtilTest {
String input = "${tit${empty}le}";
String result = "Mr.";
String jsonString = "{\"first\": \"Wim\", \"empty\": \"\", \"variables\": {\"title\": \"Mr.\", \"age\": 53}}";
- String replace = Util.replace(Util.getJson(jsonString), input);
+ JsonObject jsonObject = (JsonObject) JsonParser.parseString(jsonString);
+ String replace = Util.replace(jsonObject, input);
assertTrue(replace, replace.equals(result));
}
}

Back to the top