diff --git a/android/gradle.properties b/android/gradle.properties index b810692..6328e86 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -19,4 +19,5 @@ #systemProp.https.proxyHost=batproxy #systemProp.http.proxyPort=8080 +android.useAndroidX=true org.gradle.configureondemand=false diff --git a/android/olm-sdk/build.gradle b/android/olm-sdk/build.gradle index 294e00e..e8f0f49 100644 --- a/android/olm-sdk/build.gradle +++ b/android/olm-sdk/build.gradle @@ -6,9 +6,14 @@ android { compileSdkVersion 30 defaultConfig { - minSdkVersion 11 + minSdkVersion 14 targetSdkVersion 30 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + // The following argument makes the Android Test Orchestrator run its + // "pm clear" command after each test invocation. This command ensures + // that the app's state is completely cleared between tests. + testInstrumentationRunnerArguments clearPackageData: 'true' } buildTypes { debug { @@ -118,6 +123,8 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test:core:1.3.0' androidTestImplementation 'androidx.test:runner:1.3.0' androidTestImplementation 'androidx.test:rules:1.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' } diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java index 44405e3..3fcc9ba 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java @@ -18,12 +18,12 @@ package org.matrix.olm; import android.content.Context; -import android.support.test.runner.AndroidJUnit4; import android.text.TextUtils; import android.util.Log; -import org.json.JSONException; -import org.json.JSONObject; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -41,7 +41,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Map; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -59,15 +58,15 @@ public class OlmAccountTest { private final String FILE_NAME = "SerialTestFile"; @BeforeClass - public static void setUpClass(){ + public static void setUpClass() { // load native lib mOlmManager = new OlmManager(); String olmLibVersion = mOlmManager.getOlmLibVersion(); assertNotNull(olmLibVersion); - String olmSdkVersion = mOlmManager.getDetailedVersion(getInstrumentation().getContext()); + String olmSdkVersion = mOlmManager.getDetailedVersion(ApplicationProvider.getApplicationContext()); assertNotNull(olmLibVersion); - Log.d(LOG_TAG, "## setUpClass(): Versions - Android Olm SDK = "+olmSdkVersion+" Olm lib ="+olmLibVersion); + Log.d(LOG_TAG, "## setUpClass(): Versions - Android Olm SDK = " + olmSdkVersion + " Olm lib =" + olmLibVersion); } @AfterClass @@ -77,7 +76,7 @@ public class OlmAccountTest { @Before public void setUp() { - if(mIsAccountCreated) { + if (mIsAccountCreated) { assertNotNull(mOlmAccount); } } @@ -119,8 +118,8 @@ public class OlmAccountTest { @Test public void test04GetOlmAccountId() { long olmNativeInstance = mOlmAccount.getOlmAccountId(); - Log.d(LOG_TAG,"## testGetOlmAccountId olmNativeInstance="+olmNativeInstance); - assertTrue(0!=olmNativeInstance); + Log.d(LOG_TAG, "## testGetOlmAccountId olmNativeInstance=" + olmNativeInstance); + assertTrue(0 != olmNativeInstance); } /** @@ -137,15 +136,15 @@ public class OlmAccountTest { assertTrue("identityKeys failed " + e.getMessage(), false); } assertNotNull(identityKeys); - Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys); + Log.d(LOG_TAG, "## testIdentityKeys Keys=" + identityKeys); // is JSON_KEY_FINGER_PRINT_KEY present? String fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); - assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey)); + assertTrue("fingerprint key missing", !TextUtils.isEmpty(fingerPrintKey)); // is JSON_KEY_IDENTITY_KEY present? String identityKey = TestHelper.getIdentityKey(identityKeys); - assertTrue("identity key missing",!TextUtils.isEmpty(identityKey)); + assertTrue("identity key missing", !TextUtils.isEmpty(identityKey)); } //**************************************************** @@ -154,9 +153,9 @@ public class OlmAccountTest { @Test public void test06MaxOneTimeKeys() { long maxOneTimeKeys = mOlmAccount.maxOneTimeKeys(); - Log.d(LOG_TAG,"## testMaxOneTimeKeys(): maxOneTimeKeys="+maxOneTimeKeys); + Log.d(LOG_TAG, "## testMaxOneTimeKeys(): maxOneTimeKeys=" + maxOneTimeKeys); - assertTrue(maxOneTimeKeys>0); + assertTrue(maxOneTimeKeys > 0); } /** @@ -192,15 +191,15 @@ public class OlmAccountTest { try { Map map = oneTimeKeysJson.get(OlmAccount.JSON_KEY_ONE_TIME_KEY); - assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=map); + assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY + " object is missing", null != map); // test the count of the generated one time keys: oneTimeKeysCount = map.size(); - assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount); + assertTrue("Expected count=" + GENERATION_ONE_TIME_KEYS_NUMBER + " found=" + oneTimeKeysCount, GENERATION_ONE_TIME_KEYS_NUMBER == oneTimeKeysCount); } catch (Exception e) { - assertTrue("Exception MSg="+e.getMessage(), false); + assertTrue("Exception MSg=" + e.getMessage(), false); } } @@ -210,7 +209,7 @@ public class OlmAccountTest { try { olmSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } long sessionId = olmSession.getOlmSessionId(); assertTrue(0 != sessionId); @@ -241,7 +240,7 @@ public class OlmAccountTest { @Test public void test12SignMessage() { String clearMsg = "String to be signed by olm"; - String signedMsg = null; + String signedMsg = null; try { signedMsg = mOlmAccount.signMessage(clearMsg); @@ -268,13 +267,13 @@ public class OlmAccountTest { try { accountRef = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } try { accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER); } catch (Exception e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } // get keys references @@ -298,7 +297,7 @@ public class OlmAccountTest { assertNotNull(oneTimeKeysRef); try { - Context context = getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); //context.getFilesDir(); fileOutput = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE); @@ -316,7 +315,7 @@ public class OlmAccountTest { assertNotNull(accountDeserial); // get de-serialized keys - Map identityKeysDeserial = accountDeserial.identityKeys(); + Map identityKeysDeserial = accountDeserial.identityKeys(); Map> oneTimeKeysDeserial = accountDeserial.oneTimeKeys(); assertNotNull(identityKeysDeserial); assertNotNull(oneTimeKeysDeserial); @@ -329,23 +328,19 @@ public class OlmAccountTest { accountRef.releaseAccount(); accountDeserial.releaseAccount(); - } - catch (FileNotFoundException e) { - Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg=="+e.getMessage()); + } catch (FileNotFoundException e) { + Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg==" + e.getMessage()); assertTrue("test13Serialization failed " + e.getMessage(), false); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage()); assertTrue("test13Serialization failed " + e.getMessage(), false); - } - catch (IOException e) { + } catch (IOException e) { Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage()); assertTrue("test13Serialization failed " + e.getMessage(), false); } /*catch (OlmException e) { Log.e(LOG_TAG, "## test13Serialization(): Exception OlmException Msg==" + e.getMessage()); - }*/ - catch (Exception e) { + }*/ catch (Exception e) { Log.e(LOG_TAG, "## test13Serialization(): Exception Msg==" + e.getMessage()); assertTrue("test13Serialization failed " + e.getMessage(), false); } @@ -386,7 +381,7 @@ public class OlmAccountTest { try { olmAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } try { @@ -404,7 +399,7 @@ public class OlmAccountTest { try { olmAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } String signedMsg = null; @@ -487,7 +482,7 @@ public class OlmAccountTest { account10.releaseAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } } } diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java index 69eb0e8..57e446e 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java @@ -18,10 +18,12 @@ package org.matrix.olm; import android.content.Context; -import android.support.test.runner.AndroidJUnit4; import android.text.TextUtils; import android.util.Log; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; @@ -36,7 +38,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -223,7 +224,7 @@ public class OlmGroupSessionTest { // serialize alice session - Context context = getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); try { FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_OUT_SESSION, Context.MODE_PRIVATE); ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput); @@ -312,7 +313,7 @@ public class OlmGroupSessionTest { assertNotNull(bobInboundGroupSessionRef); // serialize alice session - Context context = getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); try { FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_IN_SESSION, Context.MODE_PRIVATE); ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput); diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java index d1e4a2e..d69be6c 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java @@ -16,20 +16,18 @@ package org.matrix.olm; -import android.support.test.runner.AndroidJUnit4; import android.util.Log; -import java.util.Arrays; +import androidx.test.ext.junit.runners.AndroidJUnit4; -import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import static org.junit.Assert.assertFalse; +import java.util.Arrays; + import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) @@ -107,14 +105,14 @@ public class OlmPkTest { assertNotNull(mOlmPkDecryption); byte[] privateKey = { - (byte)0x77, (byte)0x07, (byte)0x6D, (byte)0x0A, - (byte)0x73, (byte)0x18, (byte)0xA5, (byte)0x7D, - (byte)0x3C, (byte)0x16, (byte)0xC1, (byte)0x72, - (byte)0x51, (byte)0xB2, (byte)0x66, (byte)0x45, - (byte)0xDF, (byte)0x4C, (byte)0x2F, (byte)0x87, - (byte)0xEB, (byte)0xC0, (byte)0x99, (byte)0x2A, - (byte)0xB1, (byte)0x77, (byte)0xFB, (byte)0xA5, - (byte)0x1D, (byte)0xB9, (byte)0x2C, (byte)0x2A + (byte) 0x77, (byte) 0x07, (byte) 0x6D, (byte) 0x0A, + (byte) 0x73, (byte) 0x18, (byte) 0xA5, (byte) 0x7D, + (byte) 0x3C, (byte) 0x16, (byte) 0xC1, (byte) 0x72, + (byte) 0x51, (byte) 0xB2, (byte) 0x66, (byte) 0x45, + (byte) 0xDF, (byte) 0x4C, (byte) 0x2F, (byte) 0x87, + (byte) 0xEB, (byte) 0xC0, (byte) 0x99, (byte) 0x2A, + (byte) 0xB1, (byte) 0x77, (byte) 0xFB, (byte) 0xA5, + (byte) 0x1D, (byte) 0xB9, (byte) 0x2C, (byte) 0x2A }; assertTrue(privateKey.length == OlmPkDecryption.privateKeyLength()); diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSasTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSasTest.java index bbb50ae..50adda8 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSasTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSasTest.java @@ -16,10 +16,10 @@ package org.matrix.olm; - -import android.support.test.runner.AndroidJUnit4; import android.util.Log; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java index e08b151..a455ca2 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java @@ -18,11 +18,12 @@ package org.matrix.olm; import android.content.Context; -import android.support.test.runner.AndroidJUnit4; import android.text.TextUtils; import android.util.Log; -import org.json.JSONObject; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; @@ -37,7 +38,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Map; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -53,13 +53,13 @@ public class OlmSessionTest { private static OlmManager mOlmManager; @BeforeClass - public static void setUpClass(){ + public static void setUpClass() { // load native lib mOlmManager = new OlmManager(); String version = mOlmManager.getOlmLibVersion(); assertNotNull(version); - Log.d(LOG_TAG, "## setUpClass(): lib version="+version); + Log.d(LOG_TAG, "## setUpClass(): lib version=" + version); } /** @@ -75,7 +75,7 @@ public class OlmSessionTest { public void test01AliceToBob() { final int ONE_TIME_KEYS_NUMBER = 5; String bobIdentityKey = null; - String bobOneTimeKey=null; + String bobOneTimeKey = null; OlmAccount bobAccount = null; OlmAccount aliceAccount = null; @@ -84,12 +84,12 @@ public class OlmSessionTest { aliceAccount = new OlmAccount(); bobAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } // test accounts creation - assertTrue(0!=bobAccount.getOlmAccountId()); - assertTrue(0!=aliceAccount.getOlmAccountId()); + assertTrue(0 != bobAccount.getOlmAccountId()); + assertTrue(0 != aliceAccount.getOlmAccountId()); // get bob identity key Map bobIdentityKeys = null; @@ -101,7 +101,7 @@ public class OlmSessionTest { } bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); - assertTrue(null!=bobIdentityKey); + assertTrue(null != bobIdentityKey); // get bob one time keys try { @@ -118,7 +118,7 @@ public class OlmSessionTest { assertTrue(e.getMessage(), false); } - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -126,9 +126,9 @@ public class OlmSessionTest { try { aliceSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=aliceSession.getOlmSessionId()); + assertTrue(0 != aliceSession.getOlmSessionId()); // CREATE ALICE OUTBOUND SESSION and encrypt message to bob try { @@ -145,16 +145,16 @@ public class OlmSessionTest { } assertNotNull(encryptedMsgToBob); assertNotNull(encryptedMsgToBob.mCipherText); - Log.d(LOG_TAG,"## test01AliceToBob(): encryptedMsg="+encryptedMsgToBob.mCipherText); + Log.d(LOG_TAG, "## test01AliceToBob(): encryptedMsg=" + encryptedMsgToBob.mCipherText); // CREATE BOB INBOUND SESSION and decrypt message from alice OlmSession bobSession = null; try { bobSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=bobSession.getOlmSessionId()); + assertTrue(0 != bobSession.getOlmSessionId()); try { bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText); @@ -220,12 +220,12 @@ public class OlmSessionTest { aliceAccount = new OlmAccount(); bobAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } // test accounts creation - assertTrue(0!=bobAccount.getOlmAccountId()); - assertTrue(0!=aliceAccount.getOlmAccountId()); + assertTrue(0 != bobAccount.getOlmAccountId()); + assertTrue(0 != aliceAccount.getOlmAccountId()); // get bob identity key Map bobIdentityKeys = null; @@ -237,7 +237,7 @@ public class OlmSessionTest { } bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); - assertTrue(null!=bobIdentityKey); + assertTrue(null != bobIdentityKey); // get bob one time keys try { @@ -254,7 +254,7 @@ public class OlmSessionTest { assertTrue(e.getMessage(), false); } - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -262,9 +262,9 @@ public class OlmSessionTest { try { aliceSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=aliceSession.getOlmSessionId()); + assertTrue(0 != aliceSession.getOlmSessionId()); // CREATE ALICE OUTBOUND SESSION and encrypt message to bob try { @@ -291,10 +291,10 @@ public class OlmSessionTest { try { bobSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=bobSession.getOlmSessionId()); + assertTrue(0 != bobSession.getOlmSessionId()); try { bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText); @@ -427,12 +427,12 @@ public class OlmSessionTest { aliceAccount = new OlmAccount(); bobAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } // test accounts creation - assertTrue(0!=bobAccount.getOlmAccountId()); - assertTrue(0!=aliceAccount.getOlmAccountId()); + assertTrue(0 != bobAccount.getOlmAccountId()); + assertTrue(0 != aliceAccount.getOlmAccountId()); // CREATE ALICE SESSION @@ -440,9 +440,9 @@ public class OlmSessionTest { try { aliceSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=aliceSession.getOlmSessionId()); + assertTrue(0 != aliceSession.getOlmSessionId()); // CREATE ALICE SESSION OlmSession bobSession = null; @@ -452,7 +452,7 @@ public class OlmSessionTest { e.printStackTrace(); assertTrue(e.getMessage(), false); } - assertTrue(0!=bobSession.getOlmSessionId()); + assertTrue(0 != bobSession.getOlmSessionId()); String aliceSessionId = null; try { @@ -487,7 +487,7 @@ public class OlmSessionTest { @Test public void test04MatchInboundSession() { - OlmAccount aliceAccount=null, bobAccount=null; + OlmAccount aliceAccount = null, bobAccount = null; OlmSession aliceSession = null, bobSession = null; // ACCOUNTS CREATION @@ -601,6 +601,7 @@ public class OlmSessionTest { // ******************************************************** // ************* SERIALIZATION TEST *********************** // ******************************************************** + /** * Same as {@link #test02AliceToBobBackAndForth()}, but alice's session * is serialized and de-serialized before performing the final @@ -620,12 +621,12 @@ public class OlmSessionTest { aliceAccount = new OlmAccount(); bobAccount = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } // test accounts creation - assertTrue(0!=bobAccount.getOlmAccountId()); - assertTrue(0!=aliceAccount.getOlmAccountId()); + assertTrue(0 != bobAccount.getOlmAccountId()); + assertTrue(0 != aliceAccount.getOlmAccountId()); // get bob identity key Map bobIdentityKeys = null; @@ -637,7 +638,7 @@ public class OlmSessionTest { } bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); - assertTrue(null!=bobIdentityKey); + assertTrue(null != bobIdentityKey); // get bob one time keys try { @@ -654,7 +655,7 @@ public class OlmSessionTest { assertTrue(e.getMessage(), false); } - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -662,9 +663,9 @@ public class OlmSessionTest { try { aliceSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=aliceSession.getOlmSessionId()); + assertTrue(0 != aliceSession.getOlmSessionId()); // CREATE ALICE OUTBOUND SESSION and encrypt message to bob try { @@ -689,9 +690,9 @@ public class OlmSessionTest { try { bobSession = new OlmSession(); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } - assertTrue(0!=bobSession.getOlmSessionId()); + assertTrue(0 != bobSession.getOlmSessionId()); // init bob session with alice PRE KEY try { @@ -745,7 +746,7 @@ public class OlmSessionTest { assertNotNull(encryptedMsg3); // serialize alice session - Context context = getInstrumentation().getContext(); + Context context = ApplicationProvider.getApplicationContext(); try { FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_SESSION, Context.MODE_PRIVATE); ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput); @@ -793,23 +794,19 @@ public class OlmSessionTest { assertTrue(bobSession.isReleased()); assertTrue(aliceSession.isReleased()); assertTrue(aliceSessionDeserial.isReleased()); - } - catch (FileNotFoundException e) { - Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage()); + } catch (FileNotFoundException e) { + Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg==" + e.getMessage()); assertTrue(e.getMessage(), false); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage()); assertTrue(e.getMessage(), false); - } - catch (IOException e) { + } catch (IOException e) { Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage()); assertTrue(e.getMessage(), false); } /*catch (OlmException e) { Log.e(LOG_TAG, "## test03SessionSerialization(): Exception OlmException Msg==" + e.getMessage()); - }*/ - catch (Exception e) { + }*/ catch (Exception e) { Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage()); assertTrue(e.getMessage(), false); } @@ -862,7 +859,7 @@ public class OlmSessionTest { } assertNotNull(bobOneTimeKeys); - String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); + String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -922,7 +919,7 @@ public class OlmSessionTest { } catch (Exception e) { assertTrue(e.getMessage(), false); } - assertTrue(null==message); + assertTrue(null == message); // encrypt properly OlmMessage encryptedMsgToBob = null; @@ -974,7 +971,7 @@ public class OlmSessionTest { assertTrue(TextUtils.isEmpty(errorMessage)); } catch (OlmException e) { - assertTrue("Exception Msg="+e.getMessage(), false); + assertTrue("Exception Msg=" + e.getMessage(), false); } // SANITY CHECK TESTS FOR: decryptMessage() @@ -985,13 +982,13 @@ public class OlmSessionTest { assertTrue(e.getMessage(), false); } - assertTrue(null==decryptedMsg); + assertTrue(null == decryptedMsg); // SANITY CHECK TESTS FOR: matchesInboundSession() assertTrue(!aliceSession.matchesInboundSession(null)); // SANITY CHECK TESTS FOR: matchesInboundSessionFrom() - assertTrue(!aliceSession.matchesInboundSessionFrom(null,null)); + assertTrue(!aliceSession.matchesInboundSessionFrom(null, null)); // release objects try { diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java index b560bff..8ee7b48 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java @@ -17,11 +17,11 @@ package org.matrix.olm; -import android.support.test.runner.AndroidJUnit4; import android.text.TextUtils; import android.util.Log; -import org.json.JSONObject; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; @@ -43,13 +43,13 @@ public class OlmUtilityTest { private static OlmManager mOlmManager; @BeforeClass - public static void setUpClass(){ + public static void setUpClass() { // load native lib mOlmManager = new OlmManager(); String version = mOlmManager.getOlmLibVersion(); assertNotNull(version); - Log.d(LOG_TAG, "## setUpClass(): lib version="+version); + Log.d(LOG_TAG, "## setUpClass(): lib version=" + version); } /** @@ -66,7 +66,7 @@ public class OlmUtilityTest { try { account = new OlmAccount(); } catch (OlmException e) { - assertTrue(e.getMessage(),false); + assertTrue(e.getMessage(), false); } assertNotNull(account); @@ -92,7 +92,7 @@ public class OlmUtilityTest { assertNotNull(identityKeys); fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); - assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey)); + assertTrue("fingerprint key missing", !TextUtils.isEmpty(fingerPrintKey)); // instantiate utility object OlmUtility utility = null; @@ -124,7 +124,7 @@ public class OlmUtilityTest { assertTrue(!TextUtils.isEmpty(errorMsg)); // check bad fingerprint size => errorMsg = INVALID_BASE64 - String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2); + String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length() / 2); errorMsg = null; try {