But 1244944 - Remove untyped EJO.putAll. r?rnewman draft
authorNick Alexander <nalexander@mozilla.com>
Wed, 20 Jan 2016 16:23:44 -0800
changeset 327800 c9b80e683232112de65761bbda0d4a1a336b78e7
parent 327799 477b890ff7eb0260e9afb6d5320b3020414b68a5
child 327801 9da41d9ee4b49225cfd8a953ee8be727720b334b
push id10307
push usernalexander@mozilla.com
push dateTue, 02 Feb 2016 01:08:05 +0000
reviewersrnewman
bugs1244944
milestone47.0a1
But 1244944 - Remove untyped EJO.putAll. r?rnewman
mobile/android/services/src/main/java/org/mozilla/gecko/browserid/JSONWebTokenUtils.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/ExtendedJSONObject.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/browserid/JSONWebTokenUtils.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/browserid/JSONWebTokenUtils.java
@@ -30,24 +30,17 @@ import org.mozilla.gecko.sync.Utils;
 public class JSONWebTokenUtils {
   public static final long DEFAULT_CERTIFICATE_DURATION_IN_MILLISECONDS = 60 * 60 * 1000;
   public static final long DEFAULT_ASSERTION_DURATION_IN_MILLISECONDS = 60 * 60 * 1000;
   public static final long DEFAULT_FUTURE_EXPIRES_AT_IN_MILLISECONDS = 9999999999999L;
   public static final String DEFAULT_CERTIFICATE_ISSUER = "127.0.0.1";
   public static final String DEFAULT_ASSERTION_ISSUER = "127.0.0.1";
 
   public static String encode(String payload, SigningPrivateKey privateKey) throws UnsupportedEncodingException, GeneralSecurityException  {
-    return encode(payload, privateKey, null);
-  }
-
-  protected static String encode(String payload, SigningPrivateKey privateKey, Map<String, Object> headerFields) throws UnsupportedEncodingException, GeneralSecurityException  {
-    ExtendedJSONObject header = new ExtendedJSONObject();
-    if (headerFields != null) {
-      header.putAll(headerFields);
-    }
+    final ExtendedJSONObject header = new ExtendedJSONObject();
     header.put("alg", privateKey.getAlgorithm());
     String encodedHeader  = Base64.encodeBase64URLSafeString(header.toJSONString().getBytes("UTF-8"));
     String encodedPayload = Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8"));
     ArrayList<String> segments = new ArrayList<String>();
     segments.add(encodedHeader);
     segments.add(encodedPayload);
     byte[] message = Utils.toDelimitedString(".", segments).getBytes("UTF-8");
     byte[] signature = privateKey.signMessage(message);
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/ExtendedJSONObject.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/ExtendedJSONObject.java
@@ -289,21 +289,16 @@ public class ExtendedJSONObject {
   }
 
   public void put(String key, Object value) {
     @SuppressWarnings("unchecked")
     Map<Object, Object> map = this.object;
     map.put(key, value);
   }
 
-  @SuppressWarnings({ "unchecked", "rawtypes" })
-  public void putAll(Map map) {
-    this.object.putAll(map);
-  }
-
   /**
    * Remove key-value pair from JSONObject.
    *
    * @param key
    *          to be removed.
    * @return true if key exists and was removed, false otherwise.
    */
   public boolean remove(String key) {
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java
@@ -15,16 +15,17 @@ import org.mozilla.gecko.sync.NonObjectJ
 import org.mozilla.gecko.sync.UnexpectedJSONException.BadRequiredFieldJSONException;
 
 import java.io.IOException;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 @RunWith(TestRunner.class)
@@ -57,17 +58,16 @@ public class TestExtendedJSONObject {
     assertEquals(Long.valueOf(1233702554000L), o.getTimestamp("modified"));
     assertEquals(null, o.getTimestamp("foo"));
   }
 
   @Test
   public void testSafeInteger() {
     ExtendedJSONObject o = new ExtendedJSONObject();
     o.put("integer", Integer.valueOf(5));
-    o.put("double",  Double.valueOf(1.2));
     o.put("string",  "66");
     o.put("object",  new ExtendedJSONObject());
     o.put("null",    null);
 
     assertEquals(Integer.valueOf(5),  o.getIntegerSafely("integer"));
     assertEquals(Integer.valueOf(66), o.getIntegerSafely("string"));
     assertNull(o.getIntegerSafely(null));
   }
@@ -141,18 +141,17 @@ public class TestExtendedJSONObject {
   public void testEquals() throws Exception {
     ExtendedJSONObject o = new ExtendedJSONObject(exampleJSON);
     ExtendedJSONObject p = new ExtendedJSONObject(exampleJSON);
     assertEquals(o, p);
 
     ExtendedJSONObject q = new ExtendedJSONObject(exampleJSON);
     q.put("modified", 0);
     assertNotSame(o, q);
-    q.put("modified", o.get("modified"));
-    assertEquals(o, q);
+    assertNotEquals(o, q);
   }
 
   @Test
   public void testGetBoolean() throws Exception {
     ExtendedJSONObject o = new ExtendedJSONObject("{\"truekey\":true, \"falsekey\":false, \"stringkey\":\"string\"}");
     assertEquals(true, o.getBoolean("truekey"));
     assertEquals(false, o.getBoolean("falsekey"));
     try {