Simplify assertions using suggestion from IDE

This commit is contained in:
Benoit Marty 2021-04-16 21:57:57 +02:00
parent 1694f15ffb
commit f1d8efd821
7 changed files with 252 additions and 238 deletions

View file

@ -41,10 +41,13 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -95,12 +98,12 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount(); mOlmAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false); fail("OlmAccount failed " + e.getMessage());
} }
assertNotNull(mOlmAccount); assertNotNull(mOlmAccount);
mOlmAccount.releaseAccount(); mOlmAccount.releaseAccount();
assertTrue(0 == mOlmAccount.getOlmAccountId()); assertEquals(0, mOlmAccount.getOlmAccountId());
} }
@Test @Test
@ -109,7 +112,7 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount(); mOlmAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false); fail("OlmAccount failed " + e.getMessage());
} }
assertNotNull(mOlmAccount); assertNotNull(mOlmAccount);
mIsAccountCreated = true; mIsAccountCreated = true;
@ -133,18 +136,18 @@ public class OlmAccountTest {
try { try {
identityKeys = mOlmAccount.identityKeys(); identityKeys = mOlmAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
assertNotNull(identityKeys); assertNotNull(identityKeys);
Log.d(LOG_TAG, "## testIdentityKeys Keys=" + identityKeys); Log.d(LOG_TAG, "## testIdentityKeys Keys=" + identityKeys);
// is JSON_KEY_FINGER_PRINT_KEY present? // is JSON_KEY_FINGER_PRINT_KEY present?
String fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); String fingerPrintKey = TestHelper.getFingerprintKey(identityKeys);
assertTrue("fingerprint key missing", !TextUtils.isEmpty(fingerPrintKey)); assertFalse("fingerprint key missing", TextUtils.isEmpty(fingerPrintKey));
// is JSON_KEY_IDENTITY_KEY present? // is JSON_KEY_IDENTITY_KEY present?
String identityKey = TestHelper.getIdentityKey(identityKeys); String identityKey = TestHelper.getIdentityKey(identityKeys);
assertTrue("identity key missing", !TextUtils.isEmpty(identityKey)); assertFalse("identity key missing", TextUtils.isEmpty(identityKey));
} }
//**************************************************** //****************************************************
@ -171,7 +174,7 @@ public class OlmAccountTest {
error = e.getMessage(); error = e.getMessage();
} }
assertTrue(null == error); assertNull(error);
} }
/** /**
@ -185,21 +188,21 @@ public class OlmAccountTest {
try { try {
oneTimeKeysJson = mOlmAccount.oneTimeKeys(); oneTimeKeysJson = mOlmAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(oneTimeKeysJson); assertNotNull(oneTimeKeysJson);
try { try {
Map<String, String> map = oneTimeKeysJson.get(OlmAccount.JSON_KEY_ONE_TIME_KEY); Map<String, String> map = oneTimeKeysJson.get(OlmAccount.JSON_KEY_ONE_TIME_KEY);
assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY + " object is missing", null != map); assertNotNull(OlmAccount.JSON_KEY_ONE_TIME_KEY + " object is missing", map);
// test the count of the generated one time keys: // test the count of the generated one time keys:
oneTimeKeysCount = map.size(); oneTimeKeysCount = map.size();
assertTrue("Expected count=" + GENERATION_ONE_TIME_KEYS_NUMBER + " found=" + oneTimeKeysCount, GENERATION_ONE_TIME_KEYS_NUMBER == oneTimeKeysCount); assertEquals("Expected count=" + GENERATION_ONE_TIME_KEYS_NUMBER + " found=" + oneTimeKeysCount, GENERATION_ONE_TIME_KEYS_NUMBER, oneTimeKeysCount);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception MSg=" + e.getMessage(), false); fail("Exception MSg=" + e.getMessage());
} }
} }
@ -209,7 +212,7 @@ public class OlmAccountTest {
try { try {
olmSession = new OlmSession(); olmSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
long sessionId = olmSession.getOlmSessionId(); long sessionId = olmSession.getOlmSessionId();
assertTrue(0 != sessionId); assertTrue(0 != sessionId);
@ -221,11 +224,11 @@ public class OlmAccountTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
olmSession.releaseSession(); olmSession.releaseSession();
sessionId = olmSession.getOlmSessionId(); sessionId = olmSession.getOlmSessionId();
assertTrue(0 == sessionId); assertEquals(0, sessionId);
} }
@Test @Test
@ -233,7 +236,7 @@ public class OlmAccountTest {
try { try {
mOlmAccount.markOneTimeKeysAsPublished(); mOlmAccount.markOneTimeKeysAsPublished();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
} }
@ -245,7 +248,7 @@ public class OlmAccountTest {
try { try {
signedMsg = mOlmAccount.signMessage(clearMsg); signedMsg = mOlmAccount.signMessage(clearMsg);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(signedMsg); assertNotNull(signedMsg);
@ -262,18 +265,18 @@ public class OlmAccountTest {
FileOutputStream fileOutput; FileOutputStream fileOutput;
ObjectOutputStream objectOutput; ObjectOutputStream objectOutput;
OlmAccount accountRef = null; OlmAccount accountRef = null;
OlmAccount accountDeserial = null; OlmAccount accountDeserial;
try { try {
accountRef = new OlmAccount(); accountRef = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
try { try {
accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER); accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// get keys references // get keys references
@ -282,7 +285,7 @@ public class OlmAccountTest {
try { try {
identityKeysRef = accountRef.identityKeys(); identityKeysRef = accountRef.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
Map<String, Map<String, String>> oneTimeKeysRef = null; Map<String, Map<String, String>> oneTimeKeysRef = null;
@ -290,7 +293,7 @@ public class OlmAccountTest {
try { try {
oneTimeKeysRef = accountRef.oneTimeKeys(); oneTimeKeysRef = accountRef.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(identityKeysRef); assertNotNull(identityKeysRef);
@ -321,28 +324,28 @@ public class OlmAccountTest {
assertNotNull(oneTimeKeysDeserial); assertNotNull(oneTimeKeysDeserial);
// compare identity keys // compare identity keys
assertTrue(identityKeysDeserial.toString().equals(identityKeysRef.toString())); assertEquals(identityKeysDeserial.toString(), identityKeysRef.toString());
// compare onetime keys // compare onetime keys
assertTrue(oneTimeKeysDeserial.toString().equals(oneTimeKeysRef.toString())); assertEquals(oneTimeKeysDeserial.toString(), oneTimeKeysRef.toString());
accountRef.releaseAccount(); accountRef.releaseAccount();
accountDeserial.releaseAccount(); accountDeserial.releaseAccount();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false); fail("test13Serialization failed " + e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false); fail("test13Serialization failed " + e.getMessage());
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false); fail("test13Serialization failed " + e.getMessage());
} }
/*catch (OlmException e) { /*catch (OlmException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception OlmException Msg==" + e.getMessage()); 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()); Log.e(LOG_TAG, "## test13Serialization(): Exception Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false); fail("test13Serialization failed " + e.getMessage());
} }
} }
@ -362,7 +365,7 @@ public class OlmAccountTest {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null == errorMessage); assertNull(errorMessage);
// keys number = negative value // keys number = negative value
errorMessage = null; errorMessage = null;
@ -372,7 +375,7 @@ public class OlmAccountTest {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
} }
@Test @Test
@ -381,13 +384,13 @@ public class OlmAccountTest {
try { try {
olmAccount = new OlmAccount(); olmAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
try { try {
olmAccount.removeOneTimeKeys(null); olmAccount.removeOneTimeKeys(null);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
olmAccount.releaseAccount(); olmAccount.releaseAccount();
@ -399,7 +402,7 @@ public class OlmAccountTest {
try { try {
olmAccount = new OlmAccount(); olmAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String signedMsg = null; String signedMsg = null;
@ -444,31 +447,31 @@ public class OlmAccountTest {
String identityKey1 = TestHelper.getIdentityKey(identityKeys1); String identityKey1 = TestHelper.getIdentityKey(identityKeys1);
String identityKey2 = TestHelper.getIdentityKey(identityKeys2); String identityKey2 = TestHelper.getIdentityKey(identityKeys2);
assertFalse(identityKey1.equals(identityKey2)); assertNotEquals(identityKey1, identityKey2);
String identityKey3 = TestHelper.getIdentityKey(identityKeys3); String identityKey3 = TestHelper.getIdentityKey(identityKeys3);
assertFalse(identityKey2.equals(identityKey3)); assertNotEquals(identityKey2, identityKey3);
String identityKey4 = TestHelper.getIdentityKey(identityKeys4); String identityKey4 = TestHelper.getIdentityKey(identityKeys4);
assertFalse(identityKey3.equals(identityKey4)); assertNotEquals(identityKey3, identityKey4);
String identityKey5 = TestHelper.getIdentityKey(identityKeys5); String identityKey5 = TestHelper.getIdentityKey(identityKeys5);
assertFalse(identityKey4.equals(identityKey5)); assertNotEquals(identityKey4, identityKey5);
String identityKey6 = TestHelper.getIdentityKey(identityKeys6); String identityKey6 = TestHelper.getIdentityKey(identityKeys6);
assertFalse(identityKey5.equals(identityKey6)); assertNotEquals(identityKey5, identityKey6);
String identityKey7 = TestHelper.getIdentityKey(identityKeys7); String identityKey7 = TestHelper.getIdentityKey(identityKeys7);
assertFalse(identityKey6.equals(identityKey7)); assertNotEquals(identityKey6, identityKey7);
String identityKey8 = TestHelper.getIdentityKey(identityKeys8); String identityKey8 = TestHelper.getIdentityKey(identityKeys8);
assertFalse(identityKey7.equals(identityKey8)); assertNotEquals(identityKey7, identityKey8);
String identityKey9 = TestHelper.getIdentityKey(identityKeys9); String identityKey9 = TestHelper.getIdentityKey(identityKeys9);
assertFalse(identityKey8.equals(identityKey9)); assertNotEquals(identityKey8, identityKey9);
String identityKey10 = TestHelper.getIdentityKey(identityKeys10); String identityKey10 = TestHelper.getIdentityKey(identityKeys10);
assertFalse(identityKey9.equals(identityKey10)); assertNotEquals(identityKey9, identityKey10);
account1.releaseAccount(); account1.releaseAccount();
account2.releaseAccount(); account2.releaseAccount();
@ -482,7 +485,7 @@ public class OlmAccountTest {
account10.releaseAccount(); account10.releaseAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
} }
} }

View file

@ -38,9 +38,12 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -84,7 +87,7 @@ public class OlmGroupSessionTest {
try { try {
mAliceOutboundGroupSession = new OlmOutboundGroupSession(); mAliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
} }
} }
@ -96,7 +99,7 @@ public class OlmGroupSessionTest {
try { try {
mAliceSessionIdentifier = mAliceOutboundGroupSession.sessionIdentifier(); mAliceSessionIdentifier = mAliceOutboundGroupSession.sessionIdentifier();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(mAliceSessionIdentifier); assertNotNull(mAliceSessionIdentifier);
@ -111,7 +114,7 @@ public class OlmGroupSessionTest {
try { try {
mAliceOutboundSessionKey = mAliceOutboundGroupSession.sessionKey(); mAliceOutboundSessionKey = mAliceOutboundGroupSession.sessionKey();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(mAliceOutboundSessionKey); assertNotNull(mAliceOutboundSessionKey);
assertTrue(mAliceOutboundSessionKey.length() > 0); assertTrue(mAliceOutboundSessionKey.length() > 0);
@ -121,7 +124,7 @@ public class OlmGroupSessionTest {
public void test04GetOutboundGroupMessageIndex() { public void test04GetOutboundGroupMessageIndex() {
// test message index before any encryption // test message index before any encryption
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex(); mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(0 == mAliceMessageIndex); assertEquals(0, mAliceMessageIndex);
} }
@Test @Test
@ -130,13 +133,13 @@ public class OlmGroupSessionTest {
try { try {
mAliceToBobMessage = mAliceOutboundGroupSession.encryptMessage(CLEAR_MESSAGE1); mAliceToBobMessage = mAliceOutboundGroupSession.encryptMessage(CLEAR_MESSAGE1);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception in bob encryptMessage, Exception code=" + e.getMessage(), false); fail("Exception in bob encryptMessage, Exception code=" + e.getMessage());
} }
assertFalse(TextUtils.isEmpty(mAliceToBobMessage)); assertFalse(TextUtils.isEmpty(mAliceToBobMessage));
// test message index after encryption is incremented // test message index after encryption is incremented
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex(); mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(1 == mAliceMessageIndex); assertEquals(1, mAliceMessageIndex);
} }
@Test @Test
@ -145,7 +148,7 @@ public class OlmGroupSessionTest {
try { try {
mBobInboundGroupSession = new OlmInboundGroupSession(mAliceOutboundSessionKey); mBobInboundGroupSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode());
} }
} }
@ -157,7 +160,7 @@ public class OlmGroupSessionTest {
try { try {
mBobSessionIdentifier = mBobInboundGroupSession.sessionIdentifier(); mBobSessionIdentifier = mBobInboundGroupSession.sessionIdentifier();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertFalse(TextUtils.isEmpty(mBobSessionIdentifier)); assertFalse(TextUtils.isEmpty(mBobSessionIdentifier));
} }
@ -165,7 +168,7 @@ public class OlmGroupSessionTest {
@Test @Test
public void test09SessionIdentifiersAreIdentical() { public void test09SessionIdentifiersAreIdentical() {
// check both session identifiers are equals: alice vs bob // check both session identifiers are equals: alice vs bob
assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier)); assertEquals(mAliceSessionIdentifier, mBobSessionIdentifier);
} }
@Test @Test
@ -176,19 +179,19 @@ public class OlmGroupSessionTest {
try { try {
result = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage); result = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// test decrypted message // test decrypted message
mBobDecryptedMessage = result.mDecryptedMessage; mBobDecryptedMessage = result.mDecryptedMessage;
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage)); assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(0 == result.mIndex); assertEquals(0, result.mIndex);
} }
@Test @Test
public void test11InboundDecryptedMessageIdentical() { public void test11InboundDecryptedMessageIdentical() {
// test decrypted message // test decrypted message
assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1)); assertEquals(mBobDecryptedMessage, CLEAR_MESSAGE1);
} }
@Test @Test
@ -218,7 +221,7 @@ public class OlmGroupSessionTest {
try { try {
outboundGroupSessionRef = new OlmOutboundGroupSession(); outboundGroupSessionRef = new OlmOutboundGroupSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
} }
assertNotNull(outboundGroupSessionRef); assertNotNull(outboundGroupSessionRef);
@ -246,7 +249,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionKeySerial)); assertFalse(TextUtils.isEmpty(sessionKeySerial));
// session keys comparison // session keys comparison
assertTrue(sessionKeyRef.equals(sessionKeySerial)); assertEquals(sessionKeyRef, sessionKeySerial);
// get sessions IDs // get sessions IDs
String sessionIdRef = outboundGroupSessionRef.sessionIdentifier(); String sessionIdRef = outboundGroupSessionRef.sessionIdentifier();
@ -255,7 +258,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial)); assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison // session IDs comparison
assertTrue(sessionIdRef.equals(sessionIdSerial)); assertEquals(sessionIdRef, sessionIdSerial);
outboundGroupSessionRef.releaseSession(); outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession(); outboundGroupSessionSerial.releaseSession();
@ -264,19 +267,19 @@ public class OlmGroupSessionTest {
assertTrue(outboundGroupSessionSerial.isReleased()); assertTrue(outboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (OlmException e) { } catch (OlmException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
} }
@ -290,7 +293,7 @@ public class OlmGroupSessionTest {
try { try {
aliceOutboundGroupSession = new OlmOutboundGroupSession(); aliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
} }
assertNotNull(aliceOutboundGroupSession); assertNotNull(aliceOutboundGroupSession);
@ -300,7 +303,7 @@ public class OlmGroupSessionTest {
try { try {
sessionKeyRef = aliceOutboundGroupSession.sessionKey(); sessionKeyRef = aliceOutboundGroupSession.sessionKey();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(sessionKeyRef); assertNotNull(sessionKeyRef);
@ -308,7 +311,7 @@ public class OlmGroupSessionTest {
try { try {
bobInboundGroupSessionRef = new OlmInboundGroupSession(sessionKeyRef); bobInboundGroupSessionRef = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode());
} }
assertNotNull(bobInboundGroupSessionRef); assertNotNull(bobInboundGroupSessionRef);
@ -337,8 +340,8 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial)); assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison // session IDs comparison
assertTrue(aliceSessionId.equals(sessionIdSerial)); assertEquals(aliceSessionId, sessionIdSerial);
assertTrue(sessionIdRef.equals(sessionIdSerial)); assertEquals(sessionIdRef, sessionIdSerial);
aliceOutboundGroupSession.releaseSession(); aliceOutboundGroupSession.releaseSession();
bobInboundGroupSessionRef.releaseSession(); bobInboundGroupSessionRef.releaseSession();
@ -349,19 +352,19 @@ public class OlmGroupSessionTest {
assertTrue(bobInboundGroupSessionSerial.isReleased()); assertTrue(bobInboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (OlmException e) { } catch (OlmException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception IOException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
} }
@ -393,48 +396,48 @@ public class OlmGroupSessionTest {
// get the session key from the outbound group sessions // get the session key from the outbound group sessions
String sessionKey1 = outboundGroupSession1.sessionKey(); String sessionKey1 = outboundGroupSession1.sessionKey();
String sessionKey2 = outboundGroupSession2.sessionKey(); String sessionKey2 = outboundGroupSession2.sessionKey();
assertFalse(sessionKey1.equals(sessionKey2)); assertNotEquals(sessionKey1, sessionKey2);
String sessionKey3 = outboundGroupSession3.sessionKey(); String sessionKey3 = outboundGroupSession3.sessionKey();
assertFalse(sessionKey2.equals(sessionKey3)); assertNotEquals(sessionKey2, sessionKey3);
String sessionKey4 = outboundGroupSession4.sessionKey(); String sessionKey4 = outboundGroupSession4.sessionKey();
assertFalse(sessionKey3.equals(sessionKey4)); assertNotEquals(sessionKey3, sessionKey4);
String sessionKey5 = outboundGroupSession5.sessionKey(); String sessionKey5 = outboundGroupSession5.sessionKey();
assertFalse(sessionKey4.equals(sessionKey5)); assertNotEquals(sessionKey4, sessionKey5);
String sessionKey6 = outboundGroupSession6.sessionKey(); String sessionKey6 = outboundGroupSession6.sessionKey();
assertFalse(sessionKey5.equals(sessionKey6)); assertNotEquals(sessionKey5, sessionKey6);
String sessionKey7 = outboundGroupSession7.sessionKey(); String sessionKey7 = outboundGroupSession7.sessionKey();
assertFalse(sessionKey6.equals(sessionKey7)); assertNotEquals(sessionKey6, sessionKey7);
String sessionKey8 = outboundGroupSession8.sessionKey(); String sessionKey8 = outboundGroupSession8.sessionKey();
assertFalse(sessionKey7.equals(sessionKey8)); assertNotEquals(sessionKey7, sessionKey8);
// get the session IDs from the outbound group sessions // get the session IDs from the outbound group sessions
String sessionId1 = outboundGroupSession1.sessionIdentifier(); String sessionId1 = outboundGroupSession1.sessionIdentifier();
String sessionId2 = outboundGroupSession2.sessionIdentifier(); String sessionId2 = outboundGroupSession2.sessionIdentifier();
assertFalse(sessionId1.equals(sessionId2)); assertNotEquals(sessionId1, sessionId2);
String sessionId3 = outboundGroupSession3.sessionKey(); String sessionId3 = outboundGroupSession3.sessionKey();
assertFalse(sessionId2.equals(sessionId3)); assertNotEquals(sessionId2, sessionId3);
String sessionId4 = outboundGroupSession4.sessionKey(); String sessionId4 = outboundGroupSession4.sessionKey();
assertFalse(sessionId3.equals(sessionId4)); assertNotEquals(sessionId3, sessionId4);
String sessionId5 = outboundGroupSession5.sessionKey(); String sessionId5 = outboundGroupSession5.sessionKey();
assertFalse(sessionId4.equals(sessionId5)); assertNotEquals(sessionId4, sessionId5);
String sessionId6 = outboundGroupSession6.sessionKey(); String sessionId6 = outboundGroupSession6.sessionKey();
assertFalse(sessionId5.equals(sessionId6)); assertNotEquals(sessionId5, sessionId6);
String sessionId7 = outboundGroupSession7.sessionKey(); String sessionId7 = outboundGroupSession7.sessionKey();
assertFalse(sessionId6.equals(sessionId7)); assertNotEquals(sessionId6, sessionId7);
String sessionId8 = outboundGroupSession8.sessionKey(); String sessionId8 = outboundGroupSession8.sessionKey();
assertFalse(sessionId7.equals(sessionId8)); assertNotEquals(sessionId7, sessionId8);
outboundGroupSession1.releaseSession(); outboundGroupSession1.releaseSession();
outboundGroupSession2.releaseSession(); outboundGroupSession2.releaseSession();
@ -454,7 +457,7 @@ public class OlmGroupSessionTest {
assertTrue(outboundGroupSession7.isReleased()); assertTrue(outboundGroupSession7.isReleased());
assertTrue(outboundGroupSession8.isReleased()); assertTrue(outboundGroupSession8.isReleased());
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false); fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
} }
} }
@ -477,7 +480,7 @@ public class OlmGroupSessionTest {
try { try {
bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef); bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false); fail("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode());
} }
OlmInboundGroupSession.DecryptMessageResult result = null; OlmInboundGroupSession.DecryptMessageResult result = null;
@ -485,11 +488,11 @@ public class OlmGroupSessionTest {
try { try {
result = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji); result = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getMessage(), false); fail("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getMessage());
} }
assertNotNull(result.mDecryptedMessage); assertNotNull(result.mDecryptedMessage);
assertTrue(13 == result.mIndex); assertEquals(13, result.mIndex);
} }
/** /**
@ -509,7 +512,7 @@ public class OlmGroupSessionTest {
try { try {
bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef); bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in test19TestErrorMessageReturnedInDecrypt, Exception code=" + e.getExceptionCode(), false); fail("Exception in test19TestErrorMessageReturnedInDecrypt, Exception code=" + e.getExceptionCode());
} }
String exceptionMessage = null; String exceptionMessage = null;
@ -519,8 +522,7 @@ public class OlmGroupSessionTest {
exceptionMessage = e.getMessage(); exceptionMessage = e.getMessage();
} }
assertTrue(0!=EXPECTED_ERROR_MESSAGE.length()); assertEquals(EXPECTED_ERROR_MESSAGE, exceptionMessage);
assertTrue(EXPECTED_ERROR_MESSAGE.equals(exceptionMessage));
} }
@ -545,7 +547,7 @@ public class OlmGroupSessionTest {
try { try {
inboundGroupSession = new OlmInboundGroupSession(sessionKey); inboundGroupSession = new OlmInboundGroupSession(sessionKey);
} catch (Exception e) { } catch (Exception e) {
assertTrue("OlmInboundGroupSession failed " + e.getMessage(), false); fail("OlmInboundGroupSession failed " + e.getMessage());
} }
boolean isVerified = false; boolean isVerified = false;
@ -553,7 +555,7 @@ public class OlmGroupSessionTest {
try { try {
isVerified = inboundGroupSession.isVerified(); isVerified = inboundGroupSession.isVerified();
} catch (Exception e) { } catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false); fail("isVerified failed " + e.getMessage());
} }
assertTrue(isVerified); assertTrue(isVerified);
@ -563,26 +565,26 @@ public class OlmGroupSessionTest {
try { try {
result = inboundGroupSession.decryptMessage(message); result = inboundGroupSession.decryptMessage(message);
} catch (Exception e) { } catch (Exception e) {
assertTrue("decryptMessage failed " + e.getMessage(), false); fail("decryptMessage failed " + e.getMessage());
} }
assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message")); assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message"));
assertTrue(0 == result.mIndex); assertEquals(0, result.mIndex);
String export = null; String export = null;
try { try {
export = inboundGroupSession.export(0); export = inboundGroupSession.export(0);
} catch (Exception e) { } catch (Exception e) {
assertTrue("export failed " + e.getMessage(), false); fail("export failed " + e.getMessage());
} }
assertTrue(!TextUtils.isEmpty(export)); assertFalse(TextUtils.isEmpty(export));
long index = -1; long index = -1;
try { try {
index = inboundGroupSession.getFirstKnownIndex(); index = inboundGroupSession.getFirstKnownIndex();
} catch (Exception e) { } catch (Exception e) {
assertTrue("getFirstKnownIndex failed " + e.getMessage(), false); fail("getFirstKnownIndex failed " + e.getMessage());
} }
assertTrue(index >=0); assertTrue(index >=0);
@ -594,13 +596,13 @@ public class OlmGroupSessionTest {
try { try {
inboundGroupSession2 = inboundGroupSession.importSession(export); inboundGroupSession2 = inboundGroupSession.importSession(export);
} catch (Exception e) { } catch (Exception e) {
assertTrue("OlmInboundGroupSession failed " + e.getMessage(), false); fail("OlmInboundGroupSession failed " + e.getMessage());
} }
try { try {
isVerified = inboundGroupSession2.isVerified(); isVerified = inboundGroupSession2.isVerified();
} catch (Exception e) { } catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false); fail("isVerified failed " + e.getMessage());
} }
assertFalse(isVerified); assertFalse(isVerified);
@ -609,16 +611,16 @@ public class OlmGroupSessionTest {
try { try {
result = inboundGroupSession2.decryptMessage(message); result = inboundGroupSession2.decryptMessage(message);
} catch (Exception e) { } catch (Exception e) {
assertTrue("decryptMessage failed " + e.getMessage(), false); fail("decryptMessage failed " + e.getMessage());
} }
assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message")); assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message"));
assertTrue(0 == result.mIndex); assertEquals(0, result.mIndex);
try { try {
isVerified = inboundGroupSession2.isVerified(); isVerified = inboundGroupSession2.isVerified();
} catch (Exception e) { } catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false); fail("isVerified failed " + e.getMessage());
} }
assertTrue(isVerified); assertTrue(isVerified);

View file

@ -27,8 +27,11 @@ import org.junit.runners.MethodSorters;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -45,13 +48,13 @@ public class OlmPkTest {
mOlmPkEncryption = new OlmPkEncryption(); mOlmPkEncryption = new OlmPkEncryption();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false); fail("OlmPkEncryption failed " + e.getMessage());
} }
try { try {
mOlmPkDecryption = new OlmPkDecryption(); mOlmPkDecryption = new OlmPkDecryption();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false); fail("OlmPkEncryption failed " + e.getMessage());
} }
assertNotNull(mOlmPkEncryption); assertNotNull(mOlmPkEncryption);
@ -61,13 +64,13 @@ public class OlmPkTest {
try { try {
key = mOlmPkDecryption.generateKey(); key = mOlmPkDecryption.generateKey();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in generateKey, Exception code=" + e.getExceptionCode(), false); fail("Exception in generateKey, Exception code=" + e.getExceptionCode());
} }
Log.d(LOG_TAG, "Ephemeral Key: " + key); Log.d(LOG_TAG, "Ephemeral Key: " + key);
try { try {
mOlmPkEncryption.setRecipientKey(key); mOlmPkEncryption.setRecipientKey(key);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in setRecipientKey, Exception code=" + e.getExceptionCode(), false); fail("Exception in setRecipientKey, Exception code=" + e.getExceptionCode());
} }
String clearMessage = "Public key test"; String clearMessage = "Public key test";
@ -75,7 +78,7 @@ public class OlmPkTest {
try { try {
message = mOlmPkEncryption.encrypt(clearMessage); message = mOlmPkEncryption.encrypt(clearMessage);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in encrypt, Exception code=" + e.getExceptionCode(), false); fail("Exception in encrypt, Exception code=" + e.getExceptionCode());
} }
Log.d(LOG_TAG, "message: " + message.mCipherText + " " + message.mMac + " " + message.mEphemeralKey); Log.d(LOG_TAG, "message: " + message.mCipherText + " " + message.mMac + " " + message.mEphemeralKey);
@ -83,9 +86,9 @@ public class OlmPkTest {
try { try {
decryptedMessage = mOlmPkDecryption.decrypt(message); decryptedMessage = mOlmPkDecryption.decrypt(message);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in decrypt, Exception code=" + e.getExceptionCode(), false); fail("Exception in decrypt, Exception code=" + e.getExceptionCode());
} }
assertTrue(clearMessage.equals(decryptedMessage)); assertEquals(clearMessage, decryptedMessage);
mOlmPkEncryption.releaseEncryption(); mOlmPkEncryption.releaseEncryption();
mOlmPkDecryption.releaseDecryption(); mOlmPkDecryption.releaseDecryption();
@ -99,7 +102,7 @@ public class OlmPkTest {
mOlmPkDecryption = new OlmPkDecryption(); mOlmPkDecryption = new OlmPkDecryption();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false); fail("OlmPkEncryption failed " + e.getMessage());
} }
assertNotNull(mOlmPkDecryption); assertNotNull(mOlmPkDecryption);
@ -115,12 +118,12 @@ public class OlmPkTest {
(byte) 0x1D, (byte) 0xB9, (byte) 0x2C, (byte) 0x2A (byte) 0x1D, (byte) 0xB9, (byte) 0x2C, (byte) 0x2A
}; };
assertTrue(privateKey.length == OlmPkDecryption.privateKeyLength()); assertEquals(privateKey.length, OlmPkDecryption.privateKeyLength());
try { try {
mOlmPkDecryption.setPrivateKey(privateKey); mOlmPkDecryption.setPrivateKey(privateKey);
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in setPrivateKey, Exception code=" + e.getExceptionCode(), false); fail("Exception in setPrivateKey, Exception code=" + e.getExceptionCode());
} }
byte[] privateKeyCopy = null; byte[] privateKeyCopy = null;
@ -128,10 +131,10 @@ public class OlmPkTest {
try { try {
privateKeyCopy = mOlmPkDecryption.privateKey(); privateKeyCopy = mOlmPkDecryption.privateKey();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception in privateKey, Exception code=" + e.getExceptionCode(), false); fail("Exception in privateKey, Exception code=" + e.getExceptionCode());
} }
assertTrue(Arrays.equals(privateKey, privateKeyCopy)); assertArrayEquals(privateKey, privateKeyCopy);
mOlmPkDecryption.releaseDecryption(); mOlmPkDecryption.releaseDecryption();
assertTrue(mOlmPkDecryption.isReleased()); assertTrue(mOlmPkDecryption.isReleased());
@ -143,7 +146,7 @@ public class OlmPkTest {
mOlmPkSigning = new OlmPkSigning(); mOlmPkSigning = new OlmPkSigning();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("OlmPkSigning failed " + e.getMessage(), false); fail("OlmPkSigning failed " + e.getMessage());
} }
assertNotNull(mOlmPkSigning); assertNotNull(mOlmPkSigning);
@ -153,17 +156,17 @@ public class OlmPkTest {
seed = OlmPkSigning.generateSeed(); seed = OlmPkSigning.generateSeed();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("generateSeed failed " + e.getMessage(), false); fail("generateSeed failed " + e.getMessage());
} }
assertTrue(seed.length == OlmPkSigning.seedLength()); assertEquals(seed.length, OlmPkSigning.seedLength());
String pubkey = null; String pubkey = null;
try { try {
pubkey = mOlmPkSigning.initWithSeed(seed); pubkey = mOlmPkSigning.initWithSeed(seed);
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("initWithSeed failed " + e.getMessage(), false); fail("initWithSeed failed " + e.getMessage());
} }
String message = "We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness."; String message = "We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.";
@ -173,7 +176,7 @@ public class OlmPkTest {
signature = mOlmPkSigning.sign(message); signature = mOlmPkSigning.sign(message);
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("sign failed " + e.getMessage(), false); fail("sign failed " + e.getMessage());
} }
OlmUtility olmUtility = null; OlmUtility olmUtility = null;
@ -181,14 +184,14 @@ public class OlmPkTest {
olmUtility = new OlmUtility(); olmUtility = new OlmUtility();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("olmUtility failed " + e.getMessage(), false); fail("olmUtility failed " + e.getMessage());
} }
try { try {
olmUtility.verifyEd25519Signature(signature, pubkey, message); olmUtility.verifyEd25519Signature(signature, pubkey, message);
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue("Signature verification failed " + e.getMessage(), false); fail("Signature verification failed " + e.getMessage());
} }
mOlmPkSigning.releaseSigning(); mOlmPkSigning.releaseSigning();

View file

@ -29,6 +29,7 @@ import org.junit.runners.MethodSorters;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -91,7 +92,7 @@ public class OlmSasTest {
} catch (Exception e) { } catch (Exception e) {
assertTrue("OlmSas init failed " + e.getMessage(), false); fail("OlmSas init failed " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (aliceSas != null) { if (aliceSas != null) {

View file

@ -38,9 +38,12 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -84,7 +87,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// test accounts creation // test accounts creation
@ -97,17 +100,17 @@ public class OlmSessionTest {
try { try {
bobIdentityKeys = bobAccount.identityKeys(); bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey); assertNotNull(bobIdentityKey);
// get bob one time keys // get bob one time keys
try { try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
Map<String, Map<String, String>> bobOneTimeKeys = null; Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -115,7 +118,7 @@ public class OlmSessionTest {
try { try {
bobOneTimeKeys = bobAccount.oneTimeKeys(); bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
@ -126,7 +129,7 @@ public class OlmSessionTest {
try { try {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != aliceSession.getOlmSessionId()); assertTrue(0 != aliceSession.getOlmSessionId());
@ -134,14 +137,14 @@ public class OlmSessionTest {
try { try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey); aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String clearMsg = "Heloo bob , this is alice!"; String clearMsg = "Heloo bob , this is alice!";
OlmMessage encryptedMsgToBob = null; OlmMessage encryptedMsgToBob = null;
try { try {
encryptedMsgToBob = aliceSession.encryptMessage(clearMsg); encryptedMsgToBob = aliceSession.encryptMessage(clearMsg);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsgToBob); assertNotNull(encryptedMsgToBob);
assertNotNull(encryptedMsgToBob.mCipherText); assertNotNull(encryptedMsgToBob.mCipherText);
@ -152,32 +155,32 @@ public class OlmSessionTest {
try { try {
bobSession = new OlmSession(); bobSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != bobSession.getOlmSessionId()); assertTrue(0 != bobSession.getOlmSessionId());
try { try {
bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText); bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
} catch (Exception e) { } catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false); fail("initInboundSessionWithAccount failed " + e.getMessage());
} }
String decryptedMsg = null; String decryptedMsg = null;
try { try {
decryptedMsg = bobSession.decryptMessage(encryptedMsgToBob); decryptedMsg = bobSession.decryptMessage(encryptedMsgToBob);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg); assertNotNull(decryptedMsg);
// MESSAGE COMPARISON: decrypted vs encrypted // MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(clearMsg.equals(decryptedMsg)); assertEquals(clearMsg, decryptedMsg);
// clean objects.. // clean objects..
try { try {
bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// release accounts // release accounts
@ -220,7 +223,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// test accounts creation // test accounts creation
@ -233,17 +236,17 @@ public class OlmSessionTest {
try { try {
bobIdentityKeys = bobAccount.identityKeys(); bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey); assertNotNull(bobIdentityKey);
// get bob one time keys // get bob one time keys
try { try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
Map<String, Map<String, String>> bobOneTimeKeys = null; Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -251,7 +254,7 @@ public class OlmSessionTest {
try { try {
bobOneTimeKeys = bobAccount.oneTimeKeys(); bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
@ -262,7 +265,7 @@ public class OlmSessionTest {
try { try {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != aliceSession.getOlmSessionId()); assertTrue(0 != aliceSession.getOlmSessionId());
@ -270,7 +273,7 @@ public class OlmSessionTest {
try { try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey); aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String helloClearMsg = "Hello I'm Alice!"; String helloClearMsg = "Hello I'm Alice!";
@ -280,7 +283,7 @@ public class OlmSessionTest {
try { try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg); encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedAliceToBobMsg1); assertNotNull(encryptedAliceToBobMsg1);
@ -291,7 +294,7 @@ public class OlmSessionTest {
try { try {
bobSession = new OlmSession(); bobSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != bobSession.getOlmSessionId()); assertTrue(0 != bobSession.getOlmSessionId());
@ -299,7 +302,7 @@ public class OlmSessionTest {
try { try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText); bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) { } catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false); fail("initInboundSessionWithAccount failed " + e.getMessage());
} }
// DECRYPT MESSAGE FROM ALICE // DECRYPT MESSAGE FROM ALICE
@ -307,12 +310,12 @@ public class OlmSessionTest {
try { try {
decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1); decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg01); assertNotNull(decryptedMsg01);
// MESSAGE COMPARISON: decrypted vs encrypted // MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(helloClearMsg.equals(decryptedMsg01)); assertEquals(helloClearMsg, decryptedMsg01);
// BACK/FORTH MESSAGE COMPARISON // BACK/FORTH MESSAGE COMPARISON
String clearMsg1 = "Hello I'm Bob!"; String clearMsg1 = "Hello I'm Bob!";
@ -324,7 +327,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg1 = bobSession.encryptMessage(clearMsg1); encryptedMsg1 = bobSession.encryptMessage(clearMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg1); assertNotNull(encryptedMsg1);
@ -332,7 +335,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg2 = bobSession.encryptMessage(clearMsg2); encryptedMsg2 = bobSession.encryptMessage(clearMsg2);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg2); assertNotNull(encryptedMsg2);
@ -341,7 +344,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg3 = bobSession.encryptMessage(clearMsg3); encryptedMsg3 = bobSession.encryptMessage(clearMsg3);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg3); assertNotNull(encryptedMsg3);
@ -350,7 +353,7 @@ public class OlmSessionTest {
try { try {
decryptedMsg1 = aliceSession.decryptMessage(encryptedMsg1); decryptedMsg1 = aliceSession.decryptMessage(encryptedMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg1); assertNotNull(decryptedMsg1);
@ -358,7 +361,7 @@ public class OlmSessionTest {
try { try {
decryptedMsg2 = aliceSession.decryptMessage(encryptedMsg2); decryptedMsg2 = aliceSession.decryptMessage(encryptedMsg2);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg2); assertNotNull(decryptedMsg2);
@ -366,14 +369,14 @@ public class OlmSessionTest {
try { try {
decryptedMsg3 = aliceSession.decryptMessage(encryptedMsg3); decryptedMsg3 = aliceSession.decryptMessage(encryptedMsg3);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg3); assertNotNull(decryptedMsg3);
// comparison tests // comparison tests
assertTrue(clearMsg1.equals(decryptedMsg1)); assertEquals(clearMsg1, decryptedMsg1);
assertTrue(clearMsg2.equals(decryptedMsg2)); assertEquals(clearMsg2, decryptedMsg2);
assertTrue(clearMsg3.equals(decryptedMsg3)); assertEquals(clearMsg3, decryptedMsg3);
// and one more from alice to bob // and one more from alice to bob
clearMsg1 = "another message from Alice to Bob!!"; clearMsg1 = "another message from Alice to Bob!!";
@ -382,7 +385,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg1 = aliceSession.encryptMessage(clearMsg1); encryptedMsg1 = aliceSession.encryptMessage(clearMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg1); assertNotNull(encryptedMsg1);
@ -390,20 +393,20 @@ public class OlmSessionTest {
try { try {
decryptedMsg1 = bobSession.decryptMessage(encryptedMsg1); decryptedMsg1 = bobSession.decryptMessage(encryptedMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg1); assertNotNull(decryptedMsg1);
assertTrue(clearMsg1.equals(decryptedMsg1)); assertEquals(clearMsg1, decryptedMsg1);
// comparison test // comparison test
assertTrue(clearMsg1.equals(decryptedMsg1)); assertEquals(clearMsg1, decryptedMsg1);
// clean objects.. // clean objects..
try { try {
bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
bobAccount.releaseAccount(); bobAccount.releaseAccount();
@ -427,7 +430,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// test accounts creation // test accounts creation
@ -440,7 +443,7 @@ public class OlmSessionTest {
try { try {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != aliceSession.getOlmSessionId()); assertTrue(0 != aliceSession.getOlmSessionId());
@ -450,7 +453,7 @@ public class OlmSessionTest {
bobSession = new OlmSession(); bobSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
e.printStackTrace(); e.printStackTrace();
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertTrue(0 != bobSession.getOlmSessionId()); assertTrue(0 != bobSession.getOlmSessionId());
@ -458,7 +461,7 @@ public class OlmSessionTest {
try { try {
aliceSessionId = aliceSession.sessionIdentifier(); aliceSessionId = aliceSession.sessionIdentifier();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(aliceSessionId); assertNotNull(aliceSessionId);
@ -467,12 +470,12 @@ public class OlmSessionTest {
try { try {
bobSessionId = bobSession.sessionIdentifier(); bobSessionId = bobSession.sessionIdentifier();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(bobSessionId); assertNotNull(bobSessionId);
// must be the same for both ends of the conversation // must be the same for both ends of the conversation
assertTrue(aliceSessionId.equals(bobSessionId)); assertEquals(aliceSessionId, bobSessionId);
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
@ -495,7 +498,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// CREATE ALICE SESSION // CREATE ALICE SESSION
@ -503,7 +506,7 @@ public class OlmSessionTest {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
bobSession = new OlmSession(); bobSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
// get bob/luke identity key // get bob/luke identity key
@ -512,7 +515,7 @@ public class OlmSessionTest {
try { try {
bobIdentityKeys = bobAccount.identityKeys(); bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
Map<String, String> aliceIdentityKeys = null; Map<String, String> aliceIdentityKeys = null;
@ -520,7 +523,7 @@ public class OlmSessionTest {
try { try {
aliceIdentityKeys = aliceAccount.identityKeys(); aliceIdentityKeys = aliceAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
@ -530,13 +533,13 @@ public class OlmSessionTest {
try { try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
try { try {
aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
Map<String, Map<String, String>> bobOneTimeKeys = null; Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -544,7 +547,7 @@ public class OlmSessionTest {
try { try {
bobOneTimeKeys = bobAccount.oneTimeKeys(); bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
@ -553,7 +556,7 @@ public class OlmSessionTest {
try { try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey1); aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String aliceClearMsg = "hello helooo to bob!"; String aliceClearMsg = "hello helooo to bob!";
@ -562,7 +565,7 @@ public class OlmSessionTest {
try { try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg); encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertFalse(bobSession.matchesInboundSession(encryptedAliceToBobMsg1.mCipherText)); assertFalse(bobSession.matchesInboundSession(encryptedAliceToBobMsg1.mCipherText));
@ -571,7 +574,7 @@ public class OlmSessionTest {
try { try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText); bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) { } catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false); fail("initInboundSessionWithAccount failed " + e.getMessage());
} }
// test matchesInboundSession() and matchesInboundSessionFrom() // test matchesInboundSession() and matchesInboundSessionFrom()
@ -584,7 +587,7 @@ public class OlmSessionTest {
try { try {
bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
@ -621,7 +624,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// test accounts creation // test accounts creation
@ -634,17 +637,17 @@ public class OlmSessionTest {
try { try {
bobIdentityKeys = bobAccount.identityKeys(); bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey); assertNotNull(bobIdentityKey);
// get bob one time keys // get bob one time keys
try { try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
Map<String, Map<String, String>> bobOneTimeKeys = null; Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -652,7 +655,7 @@ public class OlmSessionTest {
try { try {
bobOneTimeKeys = bobAccount.oneTimeKeys(); bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
@ -663,7 +666,7 @@ public class OlmSessionTest {
try { try {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != aliceSession.getOlmSessionId()); assertTrue(0 != aliceSession.getOlmSessionId());
@ -671,7 +674,7 @@ public class OlmSessionTest {
try { try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey); aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
String helloClearMsg = "Hello I'm Alice!"; String helloClearMsg = "Hello I'm Alice!";
@ -680,7 +683,7 @@ public class OlmSessionTest {
try { try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg); encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedAliceToBobMsg1); assertNotNull(encryptedAliceToBobMsg1);
assertNotNull(encryptedAliceToBobMsg1.mCipherText); assertNotNull(encryptedAliceToBobMsg1.mCipherText);
@ -690,7 +693,7 @@ public class OlmSessionTest {
try { try {
bobSession = new OlmSession(); bobSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
assertTrue(0 != bobSession.getOlmSessionId()); assertTrue(0 != bobSession.getOlmSessionId());
@ -698,7 +701,7 @@ public class OlmSessionTest {
try { try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText); bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) { } catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false); fail("initInboundSessionWithAccount failed " + e.getMessage());
} }
// DECRYPT MESSAGE FROM ALICE // DECRYPT MESSAGE FROM ALICE
@ -707,13 +710,13 @@ public class OlmSessionTest {
try { try {
decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1); decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(decryptedMsg01); assertNotNull(decryptedMsg01);
// MESSAGE COMPARISON: decrypted vs encrypted // MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(helloClearMsg.equals(decryptedMsg01)); assertEquals(helloClearMsg, decryptedMsg01);
// BACK/FORTH MESSAGE COMPARISON // BACK/FORTH MESSAGE COMPARISON
String clearMsg1 = "Hello I'm Bob!"; String clearMsg1 = "Hello I'm Bob!";
@ -725,7 +728,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg1 = bobSession.encryptMessage(clearMsg1); encryptedMsg1 = bobSession.encryptMessage(clearMsg1);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg1); assertNotNull(encryptedMsg1);
@ -733,7 +736,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg2 = bobSession.encryptMessage(clearMsg2); encryptedMsg2 = bobSession.encryptMessage(clearMsg2);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg2); assertNotNull(encryptedMsg2);
@ -741,7 +744,7 @@ public class OlmSessionTest {
try { try {
encryptedMsg3 = bobSession.encryptMessage(clearMsg3); encryptedMsg3 = bobSession.encryptMessage(clearMsg3);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsg3); assertNotNull(encryptedMsg3);
@ -772,15 +775,15 @@ public class OlmSessionTest {
assertNotNull(decryptedMsg3); assertNotNull(decryptedMsg3);
// comparison tests // comparison tests
assertTrue(clearMsg1.equals(decryptedMsg1)); assertEquals(clearMsg1, decryptedMsg1);
assertTrue(clearMsg2.equals(decryptedMsg2)); assertEquals(clearMsg2, decryptedMsg2);
assertTrue(clearMsg3.equals(decryptedMsg3)); assertEquals(clearMsg3, decryptedMsg3);
// clean objects.. // clean objects..
try { try {
bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
bobAccount.releaseAccount(); bobAccount.releaseAccount();
@ -796,19 +799,19 @@ public class OlmSessionTest {
assertTrue(aliceSessionDeserial.isReleased()); assertTrue(aliceSessionDeserial.isReleased());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage()); Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
/*catch (OlmException e) { /*catch (OlmException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception OlmException Msg==" + e.getMessage()); 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()); Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
} }
@ -828,7 +831,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount(); aliceAccount = new OlmAccount();
bobAccount = new OlmAccount(); bobAccount = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
// get bob identity key // get bob identity key
@ -837,17 +840,17 @@ public class OlmSessionTest {
try { try {
bobIdentityKeys = bobAccount.identityKeys(); bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey); assertNotNull(bobIdentityKey);
// get bob one time keys // get bob one time keys
try { try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
Map<String, Map<String, String>> bobOneTimeKeys = null; Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -855,7 +858,7 @@ public class OlmSessionTest {
try { try {
bobOneTimeKeys = bobAccount.oneTimeKeys(); bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(bobOneTimeKeys); assertNotNull(bobOneTimeKeys);
@ -867,7 +870,7 @@ public class OlmSessionTest {
try { try {
aliceSession = new OlmSession(); aliceSession = new OlmSession();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
// SANITY CHECK TESTS FOR: initOutboundSessionWithAccount() // SANITY CHECK TESTS FOR: initOutboundSessionWithAccount()
@ -877,7 +880,7 @@ public class OlmSessionTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
errorMessage = null; errorMessage = null;
try { try {
@ -885,7 +888,7 @@ public class OlmSessionTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
errorMessage = null; errorMessage = null;
try { try {
@ -893,7 +896,7 @@ public class OlmSessionTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
errorMessage = null; errorMessage = null;
try { try {
@ -901,7 +904,7 @@ public class OlmSessionTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null != errorMessage); assertNotNull(errorMessage);
// init properly // init properly
errorMessage = null; errorMessage = null;
@ -910,23 +913,23 @@ public class OlmSessionTest {
} catch (Exception e) { } catch (Exception e) {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(null == errorMessage); assertNull(errorMessage);
// SANITY CHECK TESTS FOR: encryptMessage() // SANITY CHECK TESTS FOR: encryptMessage()
OlmMessage message = null; OlmMessage message = null;
try { try {
message = aliceSession.encryptMessage(null); message = aliceSession.encryptMessage(null);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertTrue(null == message); assertNull(message);
// encrypt properly // encrypt properly
OlmMessage encryptedMsgToBob = null; OlmMessage encryptedMsgToBob = null;
try { try {
encryptedMsgToBob = aliceSession.encryptMessage("A message for bob"); encryptedMsgToBob = aliceSession.encryptMessage("A message for bob");
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(encryptedMsgToBob); assertNotNull(encryptedMsgToBob);
@ -941,7 +944,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(!TextUtils.isEmpty(errorMessage)); assertFalse(TextUtils.isEmpty(errorMessage));
errorMessage = null; errorMessage = null;
try { try {
@ -950,7 +953,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(!TextUtils.isEmpty(errorMessage)); assertFalse(TextUtils.isEmpty(errorMessage));
errorMessage = null; errorMessage = null;
try { try {
@ -959,7 +962,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage(); errorMessage = e.getMessage();
} }
assertTrue(!TextUtils.isEmpty(errorMessage)); assertFalse(TextUtils.isEmpty(errorMessage));
// init properly // init properly
errorMessage = null; errorMessage = null;
@ -971,7 +974,7 @@ public class OlmSessionTest {
assertTrue(TextUtils.isEmpty(errorMessage)); assertTrue(TextUtils.isEmpty(errorMessage));
} catch (OlmException e) { } catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
// SANITY CHECK TESTS FOR: decryptMessage() // SANITY CHECK TESTS FOR: decryptMessage()
@ -979,22 +982,22 @@ public class OlmSessionTest {
try { try {
decryptedMsg = aliceSession.decryptMessage(null); decryptedMsg = aliceSession.decryptMessage(null);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertTrue(null == decryptedMsg); assertNull(decryptedMsg);
// SANITY CHECK TESTS FOR: matchesInboundSession() // SANITY CHECK TESTS FOR: matchesInboundSession()
assertTrue(!aliceSession.matchesInboundSession(null)); assertFalse(aliceSession.matchesInboundSession(null));
// SANITY CHECK TESTS FOR: matchesInboundSessionFrom() // SANITY CHECK TESTS FOR: matchesInboundSessionFrom()
assertTrue(!aliceSession.matchesInboundSessionFrom(null, null)); assertFalse(aliceSession.matchesInboundSessionFrom(null, null));
// release objects // release objects
try { try {
bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();

View file

@ -33,6 +33,7 @@ import java.util.Map;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -66,7 +67,7 @@ public class OlmUtilityTest {
try { try {
account = new OlmAccount(); account = new OlmAccount();
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(account); assertNotNull(account);
@ -76,7 +77,7 @@ public class OlmUtilityTest {
try { try {
messageSignature = account.signMessage(message); messageSignature = account.signMessage(message);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); fail(e.getMessage());
} }
assertNotNull(messageSignature); assertNotNull(messageSignature);
@ -87,12 +88,12 @@ public class OlmUtilityTest {
try { try {
identityKeys = account.identityKeys(); identityKeys = account.identityKeys();
} catch (Exception e) { } catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false); fail("identityKeys failed " + e.getMessage());
} }
assertNotNull(identityKeys); assertNotNull(identityKeys);
fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); fingerPrintKey = TestHelper.getFingerprintKey(identityKeys);
assertTrue("fingerprint key missing", !TextUtils.isEmpty(fingerPrintKey)); assertFalse("fingerprint key missing", TextUtils.isEmpty(fingerPrintKey));
// instantiate utility object // instantiate utility object
OlmUtility utility = null; OlmUtility utility = null;
@ -100,7 +101,7 @@ public class OlmUtilityTest {
try { try {
utility = new OlmUtility(); utility = new OlmUtility();
} catch (Exception e) { } catch (Exception e) {
assertTrue("failed to create OlmUtility", false); fail("failed to create OlmUtility");
} }
// verify signature // verify signature
@ -121,7 +122,7 @@ public class OlmUtilityTest {
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage(); errorMsg = e.getMessage();
} }
assertTrue(!TextUtils.isEmpty(errorMsg)); assertFalse(TextUtils.isEmpty(errorMsg));
// check bad fingerprint size => errorMsg = INVALID_BASE64 // check bad fingerprint size => errorMsg = INVALID_BASE64
String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length() / 2); String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length() / 2);
@ -132,7 +133,7 @@ public class OlmUtilityTest {
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage(); errorMsg = e.getMessage();
} }
assertTrue(!TextUtils.isEmpty(errorMsg)); assertFalse(TextUtils.isEmpty(errorMsg));
utility.releaseUtility(); utility.releaseUtility();
assertTrue(utility.isReleased()); assertTrue(utility.isReleased());
@ -148,7 +149,7 @@ public class OlmUtilityTest {
try { try {
utility = new OlmUtility(); utility = new OlmUtility();
} catch (Exception e) { } catch (Exception e) {
assertTrue("OlmUtility creation failed", false); fail("OlmUtility creation failed");
} }
String msgToHash = "The quick brown fox jumps over the lazy dog"; String msgToHash = "The quick brown fox jumps over the lazy dog";

View file

@ -22,6 +22,7 @@ import java.util.Map;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* Helper class providing helper methods used in the Olm Android SDK unit tests. * Helper class providing helper methods used in the Olm Android SDK unit tests.
@ -39,7 +40,7 @@ public class TestHelper {
try { try {
idKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_IDENTITY_KEY); idKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_IDENTITY_KEY);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception MSg=" + e.getMessage(), false); fail("Exception MSg=" + e.getMessage());
} }
return idKey; return idKey;
} }
@ -55,7 +56,7 @@ public class TestHelper {
try { try {
fingerprintKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_FINGER_PRINT_KEY); fingerprintKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_FINGER_PRINT_KEY);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception MSg=" + e.getMessage(), false); fail("Exception MSg=" + e.getMessage());
} }
return fingerprintKey; return fingerprintKey;
} }
@ -75,7 +76,7 @@ public class TestHelper {
firstOneTimeKey = (new ArrayList<>(generatedKeys.values())).get(aKeyPosition - 1); firstOneTimeKey = (new ArrayList<>(generatedKeys.values())).get(aKeyPosition - 1);
} catch (Exception e) { } catch (Exception e) {
assertTrue("Exception Msg=" + e.getMessage(), false); fail("Exception Msg=" + e.getMessage());
} }
return firstOneTimeKey; return firstOneTimeKey;
} }