But 1244944 - Remove untyped EJO.putAll. r?rnewman
draft
But 1244944 - Remove untyped EJO.putAll. r?rnewman
--- 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 {