Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2018-04-29 15:35:31 -0400
committerWim Jongman2018-04-29 16:28:12 -0400
commit0042755f51c37aa19cf5f0cfea5259ef71437683 (patch)
tree196ec3a8da994187c62f542367da48c17952deac /org.eclipse.tips.tests/src/org/eclipse/tips
parentfde39fc97b47e4743249cbd96c62985967700bda (diff)
downloadeclipse.platform.ua-0042755f51c37aa19cf5f0cfea5259ef71437683.tar.gz
eclipse.platform.ua-0042755f51c37aa19cf5f0cfea5259ef71437683.tar.xz
eclipse.platform.ua-0042755f51c37aa19cf5f0cfea5259ef71437683.zip
Bug 534073: [Tips] Create JSon based Tip Provider for PlatformI20180430-0715I20180429-2000
* Added photon new and noteworthy provider * Changed startup sequence * Added logging * Removed warnings from examples * Fixed Twitter Feed to not use the Twitter URL * Added TipProvider#hasContent * Changes IUrlTip#getURL Change-Id: I100d32c49d27d850697ae1f347282d99d52417e2 Signed-off-by: Wim Jongman <wim.jongman@remainsoftware.com>
Diffstat (limited to 'org.eclipse.tips.tests/src/org/eclipse/tips')
-rw-r--r--org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java69
-rw-r--r--org.eclipse.tips.tests/src/org/eclipse/tips/manual/tests/SleakTipManager.java3
2 files changed, 70 insertions, 2 deletions
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
new file mode 100644
index 000000000..7e16c41a6
--- /dev/null
+++ b/org.eclipse.tips.tests/src/org/eclipse/tips/json/internal/UtilTest.java
@@ -0,0 +1,69 @@
+package org.eclipse.tips.json.internal;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import com.google.gson.JsonObject;
+
+public class UtilTest {
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testGetValueOrDefaultJsonObjectStringString() throws IOException {
+ String jsonString = "{\"first\": \"Wim\", \"last\": \"Jongman\", \"variables\": {\"title\": \"Mr.\", \"age\": 53}}";
+ JsonObject jsonObject = Util.getJson(jsonString);
+ assertTrue(Util.getValueOrDefault(jsonObject, "first", "Mark").equals("Wim"));
+ assertTrue(Util.getValueOrDefault(jsonObject, "fake", "Mark").equals("Mark"));
+ }
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testGetValueOrDefaultJsonObjectStringInt() throws IOException {
+ String jsonString = "{\"age\": \"53\", \"last\": \"Jongman\"}";
+ JsonObject jsonObject = Util.getJson(jsonString);
+ assertTrue(Util.getValueOrDefault(jsonObject, "age", 100) == 53);
+ assertTrue(Util.getValueOrDefault(jsonObject, "fake", 101) == 101);
+ }
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testGetValueOrDefaultJsonObjectStringDouble() throws IOException {
+ String jsonString = "{\"double\": 5.21, \"last\": \"Jongman\"}";
+ JsonObject jsonObject = Util.getJson(jsonString);
+ assertTrue(Util.getValueOrDefault(jsonObject, "double", 10.10) == 5.21);
+ assertTrue(Util.getValueOrDefault(jsonObject, "fake", 101.6) == 101.6);
+ }
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testReplace() throws IOException {
+ 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);
+ assertTrue(replace, replace.equals(result));
+ }
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testReplace2() throws IOException {
+ 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);
+ assertTrue(replace, replace.equals(result));
+ }
+
+ @SuppressWarnings("restriction")
+ @Test
+ public void testReplace3() throws IOException {
+ 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);
+ assertTrue(replace, replace.equals(result));
+ }
+}
diff --git a/org.eclipse.tips.tests/src/org/eclipse/tips/manual/tests/SleakTipManager.java b/org.eclipse.tips.tests/src/org/eclipse/tips/manual/tests/SleakTipManager.java
index 20fa208c0..9d2de1702 100644
--- a/org.eclipse.tips.tests/src/org/eclipse/tips/manual/tests/SleakTipManager.java
+++ b/org.eclipse.tips.tests/src/org/eclipse/tips/manual/tests/SleakTipManager.java
@@ -122,8 +122,7 @@ public class SleakTipManager extends TipManager {
@Override
public ITipManager log(IStatus pStatus) {
- // TODO Auto-generated method stub
- return null;
+ return this;
}
@Override

Back to the top