Update Account unit tests

This commit is contained in:
pedroGitt 2016-10-06 10:30:24 +02:00
parent 573713dd00
commit 0393ad6843
2 changed files with 17 additions and 16 deletions

View file

@ -15,9 +15,9 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; 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.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@ -93,7 +93,7 @@ public class OlmAccountTest {
try { try {
String fingerPrintKey = identityKeysJson.getString(OlmAccount.JSON_KEY_FINGER_PRINT_KEY); 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("Exception MSg="+e.getMessage(), false); assertTrue("Exception MSg="+e.getMessage(), false);
@ -101,7 +101,7 @@ public class OlmAccountTest {
try { try {
String identityKey = identityKeysJson.getString(OlmAccount.JSON_KEY_IDENTITY_KEY); 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("Exception MSg="+e.getMessage(), false); assertTrue("Exception MSg="+e.getMessage(), false);
@ -110,7 +110,6 @@ public class OlmAccountTest {
} }
//**************************************************** //****************************************************
//** ************** One time keys TESTS ************** //** ************** One time keys TESTS **************
//**************************************************** //****************************************************
@ -133,20 +132,24 @@ public class OlmAccountTest {
@Test @Test
public void test7OneTimeKeysJsonFormat() { public void test7OneTimeKeysJsonFormat() {
Log.d(LOG_TAG,"## testIdentityKeys"); Log.d(LOG_TAG,"## test7OneTimeKeysJsonFormat");
int oneTimeKeysCount = 0;
JSONObject generatedKeysJsonObj; JSONObject generatedKeysJsonObj;
JSONObject oneTimeKeysJson = mOlmAccount.oneTimeKeys(); JSONObject oneTimeKeysJson = mOlmAccount.oneTimeKeys();
assertNotNull(oneTimeKeysJson); assertNotNull(oneTimeKeysJson);
try { try {
generatedKeysJsonObj = oneTimeKeysJson.getJSONObject(OlmAccount.JSON_KEY_ONE_TIME_KEY); 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); // test the count of the generated one time keys:
assertFalse(" one time KeyA object is missing", TextUtils.isEmpty(oneTimeKeyA)); Iterator<String> 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) { } catch (JSONException e) {
assertTrue("Exception MSg="+e.getMessage(), false); assertTrue("Exception MSg="+e.getMessage(), false);
} }

View file

@ -25,11 +25,9 @@ public class OlmAccount {
private static final String LOG_TAG = "OlmAccount"; private static final String LOG_TAG = "OlmAccount";
// JSON keys used in the JSON objects returned by JNI // JSON keys used in the JSON objects returned by JNI
public static String JSON_KEY_ONE_TIME_KEY = "curve25519"; public static final String JSON_KEY_ONE_TIME_KEY = "curve25519";
public static String JSON_KEY_IDENTITY_KEY = "curve25519"; public static final String JSON_KEY_IDENTITY_KEY = "curve25519";
public static String JSON_KEY_FINGER_PRINT_KEY = "ed25519"; public static final 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";
/** instance unique identifier, used in JNI to match the corresponding native class **/ /** instance unique identifier, used in JNI to match the corresponding native class **/
private int mJavaInstanceId; private int mJavaInstanceId;