You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ss...@apache.org on 2012/08/11 22:09:17 UTC

svn commit: r1372015 - in /shindig/trunk/java: common/src/test/java/org/apache/shindig/common/JsonAssert.java gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java

Author: ssievers
Date: Sat Aug 11 20:09:17 2012
New Revision: 1372015

URL: http://svn.apache.org/viewvc?rev=1372015&view=rev
Log:
SHINDIG-1838 | RenderingGadgetRewriterTest.xhrWrapperConfigurationInjected fails in Java 5 builds

Modified:
    shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java

Modified: shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java?rev=1372015&r1=1372014&r2=1372015&view=diff
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java (original)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java Sat Aug 11 20:09:17 2012
@@ -29,6 +29,11 @@ public final class JsonAssert {
   private JsonAssert() {}
 
   public static void assertJsonArrayEquals(JSONArray expected, JSONArray actual) throws Exception {
+    assertJsonArrayEquals(null, expected, actual);
+  }
+
+  public static void assertJsonArrayEquals(String message, JSONArray expected, JSONArray actual)
+          throws Exception {
     if (expected.length() != actual.length()) {
       assertEquals("Arrays are not of equal length", expected.toString(), actual.toString());
     }
@@ -37,20 +42,26 @@ public final class JsonAssert {
       Object expectedValue = expected.opt(i);
       Object actualValue = actual.opt(i);
 
-      assertSame(expected.toString() + " != " + actual.toString(),
-                   expectedValue.getClass(), actualValue.getClass());
+      assertSame(expected.toString() + " != " + actual.toString(), expectedValue.getClass(),
+              actualValue.getClass());
 
       if (expectedValue instanceof JSONObject) {
-        assertJsonObjectEquals((JSONObject) expectedValue, (JSONObject) actualValue);
+        assertJsonObjectEquals(message, (JSONObject) expectedValue, (JSONObject) actualValue);
       } else if (expectedValue instanceof JSONArray) {
-        assertJsonArrayEquals((JSONArray) expectedValue, (JSONArray) actualValue);
+        assertJsonArrayEquals(message, (JSONArray) expectedValue, (JSONArray) actualValue);
       } else {
         assertEquals(expectedValue, actualValue);
       }
     }
   }
 
-  public static void assertJsonObjectEquals(JSONObject expected, JSONObject actual) throws Exception {
+  public static void assertJsonObjectEquals(JSONObject expected, JSONObject actual)
+          throws Exception {
+    assertJsonObjectEquals(null, expected, actual);
+  }
+
+  public static void assertJsonObjectEquals(String message, JSONObject expected, JSONObject actual)
+          throws Exception {
     if (expected.length() != actual.length()) {
       assertEquals("Objects are not of equal size", expected.toString(2), actual.toString(2));
     }
@@ -66,13 +77,13 @@ public final class JsonAssert {
       if (expectedValue != null) {
         assertNotNull(expected.toString() + " != " + actual.toString(), actualValue);
       }
-      assertSame(expected.toString() + " != " + actual.toString(),
-                 expectedValue.getClass(), actualValue.getClass());
+      assertSame(expected.toString() + " != " + actual.toString(), expectedValue.getClass(),
+              actualValue.getClass());
 
       if (expectedValue instanceof JSONObject) {
-        assertJsonObjectEquals((JSONObject) expectedValue, (JSONObject) actualValue);
+        assertJsonObjectEquals(message, (JSONObject) expectedValue, (JSONObject) actualValue);
       } else if (expectedValue instanceof JSONArray) {
-        assertJsonArrayEquals((JSONArray) expectedValue, (JSONArray) actualValue);
+        assertJsonArrayEquals(message, (JSONArray) expectedValue, (JSONArray) actualValue);
       } else {
         assertEquals(expectedValue, actualValue);
       }
@@ -80,28 +91,38 @@ public final class JsonAssert {
   }
 
   public static void assertJsonEquals(String expected, String actual) throws Exception {
+    assertJsonEquals(null, expected, actual);
+  }
+
+  public static void assertJsonEquals(String message, String expected, String actual)
+          throws Exception {
     switch (expected.charAt(0)) {
-      case '{':
-        assertJsonObjectEquals(new JSONObject(expected), new JSONObject(actual));
-        break;
-      case '[':
-        assertJsonArrayEquals(new JSONArray(expected), new JSONArray(actual));
-        break;
-      default:
-        assertEquals(expected, actual);
-        break;
+    case '{':
+      assertJsonObjectEquals(message, new JSONObject(expected), new JSONObject(actual));
+      break;
+    case '[':
+      assertJsonArrayEquals(message, new JSONArray(expected), new JSONArray(actual));
+      break;
+    default:
+      assertEquals(expected, actual);
+      break;
     }
   }
 
   public static void assertObjectEquals(Object expected, Object actual) throws Exception {
+    assertObjectEquals(null, expected, actual);
+  }
+
+  public static void assertObjectEquals(String message, Object expected, Object actual)
+          throws Exception {
     if (!(expected instanceof String)) {
       expected = JsonSerializer.serialize(expected);
     }
 
-    if (!(actual instanceof String)){
+    if (!(actual instanceof String)) {
       actual = JsonSerializer.serialize(actual);
     }
 
-    assertJsonEquals((String) expected, (String) actual);
+    assertJsonEquals(message, (String) expected, (String) actual);
   }
 }

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java?rev=1372015&r1=1372014&r2=1372015&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingGadgetRewriterTest.java Sat Aug 11 20:09:17 2012
@@ -930,7 +930,7 @@ public class RenderingGadgetRewriterTest
     JSONObject config = new JSONObject(configJson);
     JSONObject xhrConfig = config.getJSONObject("shindig.xhrwrapper");
     JSONObject expectedJson = new JSONObject(expected);
-    assertEquals(message, xhrConfig.toString(), expectedJson.toString());
+    JsonAssert.assertJsonObjectEquals(xhrConfig, expectedJson);
   }
 
   @Test