From 0393ad68438669f60a6679c9e0f8010c7366c5ed Mon Sep 17 00:00:00 2001 From: pedroGitt Date: Thu, 6 Oct 2016 10:30:24 +0200 Subject: Update Account unit tests --- .../java/org/matrix/olm/OlmAccountTest.java | 25 ++++++++++++---------- .../src/main/java/org/matrix/olm/OlmAccount.java | 8 +++---- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'java/android') diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java index 3d7568f..061c79d 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java @@ -15,9 +15,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import static org.junit.Assert.assertFalse; +import java.util.Iterator; + import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) @@ -93,7 +93,7 @@ public class OlmAccountTest { try { String fingerPrintKey = identityKeysJson.getString(OlmAccount.JSON_KEY_FINGER_PRINT_KEY); - assertFalse("fingerprint key missing",TextUtils.isEmpty(fingerPrintKey)); + assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey)); } catch (JSONException e) { e.printStackTrace(); assertTrue("Exception MSg="+e.getMessage(), false); @@ -101,7 +101,7 @@ public class OlmAccountTest { try { String identityKey = identityKeysJson.getString(OlmAccount.JSON_KEY_IDENTITY_KEY); - assertFalse("identity key missing",TextUtils.isEmpty(identityKey)); + assertTrue("identity key missing",!TextUtils.isEmpty(identityKey)); } catch (JSONException e) { e.printStackTrace(); assertTrue("Exception MSg="+e.getMessage(), false); @@ -110,7 +110,6 @@ public class OlmAccountTest { } - //**************************************************** //** ************** One time keys TESTS ************** //**************************************************** @@ -133,20 +132,24 @@ public class OlmAccountTest { @Test public void test7OneTimeKeysJsonFormat() { - Log.d(LOG_TAG,"## testIdentityKeys"); + Log.d(LOG_TAG,"## test7OneTimeKeysJsonFormat"); + int oneTimeKeysCount = 0; JSONObject generatedKeysJsonObj; JSONObject oneTimeKeysJson = mOlmAccount.oneTimeKeys(); assertNotNull(oneTimeKeysJson); try { generatedKeysJsonObj = oneTimeKeysJson.getJSONObject(OlmAccount.JSON_KEY_ONE_TIME_KEY); - assertFalse(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null==generatedKeysJsonObj); + assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=generatedKeysJsonObj); - /*String oneTimeKeyA = generatedKeysJsonObj.getString(OlmAccount.JSON_KEY_ONE_TIME_KEY_GENERATED_A); - assertFalse(" one time KeyA object is missing", TextUtils.isEmpty(oneTimeKeyA)); + // test the count of the generated one time keys: + Iterator generatedKeysIt = generatedKeysJsonObj.keys(); + while(generatedKeysIt.hasNext()){ + generatedKeysIt.next(); + oneTimeKeysCount++; + } + assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount); - String oneTimeKeyB = generatedKeysJsonObj.getString(OlmAccount.JSON_KEY_ONE_TIME_KEY_GENERATED_B); - assertFalse(" one time KeyA object is missing", TextUtils.isEmpty(oneTimeKeyA));*/ } catch (JSONException e) { assertTrue("Exception MSg="+e.getMessage(), false); } diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java index ac8e12d..15de09c 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java +++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java @@ -25,11 +25,9 @@ public class OlmAccount { private static final String LOG_TAG = "OlmAccount"; // JSON keys used in the JSON objects returned by JNI - public static String JSON_KEY_ONE_TIME_KEY = "curve25519"; - public static String JSON_KEY_IDENTITY_KEY = "curve25519"; - public static String JSON_KEY_FINGER_PRINT_KEY = "ed25519"; - public static String JSON_KEY_ONE_TIME_KEY_GENERATED_A = "AAAAAA"; - public static String JSON_KEY_ONE_TIME_KEY_GENERATED_B = "AAAAAB"; + public static final String JSON_KEY_ONE_TIME_KEY = "curve25519"; + public static final String JSON_KEY_IDENTITY_KEY = "curve25519"; + public static final String JSON_KEY_FINGER_PRINT_KEY = "ed25519"; /** instance unique identifier, used in JNI to match the corresponding native class **/ private int mJavaInstanceId; -- cgit v1.2.3