Commit f1d8efd8 authored by Benoit Marty's avatar Benoit Marty
Browse files

Simplify assertions using suggestion from IDE

parent 1694f15f
......@@ -41,10 +41,13 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
......@@ -95,12 +98,12 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false);
fail("OlmAccount failed " + e.getMessage());
}
assertNotNull(mOlmAccount);
mOlmAccount.releaseAccount();
assertTrue(0 == mOlmAccount.getOlmAccountId());
assertEquals(0, mOlmAccount.getOlmAccountId());
}
@Test
......@@ -109,7 +112,7 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false);
fail("OlmAccount failed " + e.getMessage());
}
assertNotNull(mOlmAccount);
mIsAccountCreated = true;
......@@ -133,18 +136,18 @@ public class OlmAccountTest {
try {
identityKeys = mOlmAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
assertNotNull(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));
assertFalse("fingerprint key missing", TextUtils.isEmpty(fingerPrintKey));
// is JSON_KEY_IDENTITY_KEY present?
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();
}
assertTrue(null == error);
assertNull(error);
}
/**
......@@ -185,21 +188,21 @@ public class OlmAccountTest {
try {
oneTimeKeysJson = mOlmAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(oneTimeKeysJson);
try {
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:
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) {
assertTrue("Exception MSg=" + e.getMessage(), false);
fail("Exception MSg=" + e.getMessage());
}
}
......@@ -209,7 +212,7 @@ public class OlmAccountTest {
try {
olmSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
long sessionId = olmSession.getOlmSessionId();
assertTrue(0 != sessionId);
......@@ -221,11 +224,11 @@ public class OlmAccountTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
olmSession.releaseSession();
sessionId = olmSession.getOlmSessionId();
assertTrue(0 == sessionId);
assertEquals(0, sessionId);
}
@Test
......@@ -233,7 +236,7 @@ public class OlmAccountTest {
try {
mOlmAccount.markOneTimeKeysAsPublished();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
......@@ -245,7 +248,7 @@ public class OlmAccountTest {
try {
signedMsg = mOlmAccount.signMessage(clearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(signedMsg);
......@@ -262,18 +265,18 @@ public class OlmAccountTest {
FileOutputStream fileOutput;
ObjectOutputStream objectOutput;
OlmAccount accountRef = null;
OlmAccount accountDeserial = null;
OlmAccount accountDeserial;
try {
accountRef = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
try {
accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// get keys references
......@@ -282,7 +285,7 @@ public class OlmAccountTest {
try {
identityKeysRef = accountRef.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
Map<String, Map<String, String>> oneTimeKeysRef = null;
......@@ -290,7 +293,7 @@ public class OlmAccountTest {
try {
oneTimeKeysRef = accountRef.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(identityKeysRef);
......@@ -321,28 +324,28 @@ public class OlmAccountTest {
assertNotNull(oneTimeKeysDeserial);
// compare identity keys
assertTrue(identityKeysDeserial.toString().equals(identityKeysRef.toString()));
assertEquals(identityKeysDeserial.toString(), identityKeysRef.toString());
// compare onetime keys
assertTrue(oneTimeKeysDeserial.toString().equals(oneTimeKeysRef.toString()));
assertEquals(oneTimeKeysDeserial.toString(), oneTimeKeysRef.toString());
accountRef.releaseAccount();
accountDeserial.releaseAccount();
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
fail("test13Serialization failed " + e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
fail("test13Serialization failed " + e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
fail("test13Serialization failed " + e.getMessage());
}
/*catch (OlmException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception OlmException Msg==" + e.getMessage());
}*/ catch (Exception e) {
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();
}
assertTrue(null == errorMessage);
assertNull(errorMessage);
// keys number = negative value
errorMessage = null;
......@@ -372,7 +375,7 @@ public class OlmAccountTest {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
}
@Test
......@@ -381,13 +384,13 @@ public class OlmAccountTest {
try {
olmAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
try {
olmAccount.removeOneTimeKeys(null);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
olmAccount.releaseAccount();
......@@ -399,7 +402,7 @@ public class OlmAccountTest {
try {
olmAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String signedMsg = null;
......@@ -444,31 +447,31 @@ public class OlmAccountTest {
String identityKey1 = TestHelper.getIdentityKey(identityKeys1);
String identityKey2 = TestHelper.getIdentityKey(identityKeys2);
assertFalse(identityKey1.equals(identityKey2));
assertNotEquals(identityKey1, identityKey2);
String identityKey3 = TestHelper.getIdentityKey(identityKeys3);
assertFalse(identityKey2.equals(identityKey3));
assertNotEquals(identityKey2, identityKey3);
String identityKey4 = TestHelper.getIdentityKey(identityKeys4);
assertFalse(identityKey3.equals(identityKey4));
assertNotEquals(identityKey3, identityKey4);
String identityKey5 = TestHelper.getIdentityKey(identityKeys5);
assertFalse(identityKey4.equals(identityKey5));
assertNotEquals(identityKey4, identityKey5);
String identityKey6 = TestHelper.getIdentityKey(identityKeys6);
assertFalse(identityKey5.equals(identityKey6));
assertNotEquals(identityKey5, identityKey6);
String identityKey7 = TestHelper.getIdentityKey(identityKeys7);
assertFalse(identityKey6.equals(identityKey7));
assertNotEquals(identityKey6, identityKey7);
String identityKey8 = TestHelper.getIdentityKey(identityKeys8);
assertFalse(identityKey7.equals(identityKey8));
assertNotEquals(identityKey7, identityKey8);
String identityKey9 = TestHelper.getIdentityKey(identityKeys9);
assertFalse(identityKey8.equals(identityKey9));
assertNotEquals(identityKey8, identityKey9);
String identityKey10 = TestHelper.getIdentityKey(identityKeys10);
assertFalse(identityKey9.equals(identityKey10));
assertNotEquals(identityKey9, identityKey10);
account1.releaseAccount();
account2.releaseAccount();
......@@ -482,7 +485,7 @@ public class OlmAccountTest {
account10.releaseAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
}
......@@ -38,9 +38,12 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
......@@ -84,7 +87,7 @@ public class OlmGroupSessionTest {
try {
mAliceOutboundGroupSession = new OlmOutboundGroupSession();
} 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 {
mAliceSessionIdentifier = mAliceOutboundGroupSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(mAliceSessionIdentifier);
......@@ -111,7 +114,7 @@ public class OlmGroupSessionTest {
try {
mAliceOutboundSessionKey = mAliceOutboundGroupSession.sessionKey();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(mAliceOutboundSessionKey);
assertTrue(mAliceOutboundSessionKey.length() > 0);
......@@ -121,7 +124,7 @@ public class OlmGroupSessionTest {
public void test04GetOutboundGroupMessageIndex() {
// test message index before any encryption
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(0 == mAliceMessageIndex);
assertEquals(0, mAliceMessageIndex);
}
@Test
......@@ -130,13 +133,13 @@ public class OlmGroupSessionTest {
try {
mAliceToBobMessage = mAliceOutboundGroupSession.encryptMessage(CLEAR_MESSAGE1);
} 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));
// test message index after encryption is incremented
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(1 == mAliceMessageIndex);
assertEquals(1, mAliceMessageIndex);
}
@Test
......@@ -145,7 +148,7 @@ public class OlmGroupSessionTest {
try {
mBobInboundGroupSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
} 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 {
mBobSessionIdentifier = mBobInboundGroupSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertFalse(TextUtils.isEmpty(mBobSessionIdentifier));
}
......@@ -165,7 +168,7 @@ public class OlmGroupSessionTest {
@Test
public void test09SessionIdentifiersAreIdentical() {
// check both session identifiers are equals: alice vs bob
assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
assertEquals(mAliceSessionIdentifier, mBobSessionIdentifier);
}
@Test
......@@ -176,19 +179,19 @@ public class OlmGroupSessionTest {
try {
result = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// test decrypted message
mBobDecryptedMessage = result.mDecryptedMessage;
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(0 == result.mIndex);
assertEquals(0, result.mIndex);
}
@Test
public void test11InboundDecryptedMessageIdentical() {
// test decrypted message
assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1));
assertEquals(mBobDecryptedMessage, CLEAR_MESSAGE1);
}
@Test
......@@ -218,7 +221,7 @@ public class OlmGroupSessionTest {
try {
outboundGroupSessionRef = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(outboundGroupSessionRef);
......@@ -246,7 +249,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionKeySerial));
// session keys comparison
assertTrue(sessionKeyRef.equals(sessionKeySerial));
assertEquals(sessionKeyRef, sessionKeySerial);
// get sessions IDs
String sessionIdRef = outboundGroupSessionRef.sessionIdentifier();
......@@ -255,7 +258,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison
assertTrue(sessionIdRef.equals(sessionIdSerial));
assertEquals(sessionIdRef, sessionIdSerial);
outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession();
......@@ -264,19 +267,19 @@ public class OlmGroupSessionTest {
assertTrue(outboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (OlmException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (Exception e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
......@@ -290,7 +293,7 @@ public class OlmGroupSessionTest {
try {
aliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(aliceOutboundGroupSession);
......@@ -300,7 +303,7 @@ public class OlmGroupSessionTest {
try {
sessionKeyRef = aliceOutboundGroupSession.sessionKey();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(sessionKeyRef);
......@@ -308,7 +311,7 @@ public class OlmGroupSessionTest {
try {
bobInboundGroupSessionRef = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) {
assertTrue("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(bobInboundGroupSessionRef);
......@@ -337,8 +340,8 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison
assertTrue(aliceSessionId.equals(sessionIdSerial));
assertTrue(sessionIdRef.equals(sessionIdSerial));
assertEquals(aliceSessionId, sessionIdSerial);
assertEquals(sessionIdRef, sessionIdSerial);
aliceOutboundGroupSession.releaseSession();
bobInboundGroupSessionRef.releaseSession();
......@@ -349,19 +352,19 @@ public class OlmGroupSessionTest {
assertTrue(bobInboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (OlmException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (Exception e) {
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
String sessionKey1 = outboundGroupSession1.sessionKey();
String sessionKey2 = outboundGroupSession2.sessionKey();
assertFalse(sessionKey1.equals(sessionKey2));
assertNotEquals(sessionKey1, sessionKey2);
String sessionKey3 = outboundGroupSession3.sessionKey();
assertFalse(sessionKey2.equals(sessionKey3));
assertNotEquals(sessionKey2, sessionKey3);
String sessionKey4 = outboundGroupSession4.sessionKey();
assertFalse(sessionKey3.equals(sessionKey4));
assertNotEquals(sessionKey3, sessionKey4);
String sessionKey5 = outboundGroupSession5.sessionKey();
assertFalse(sessionKey4.equals(sessionKey5));
assertNotEquals(sessionKey4, sessionKey5);
String sessionKey6 = outboundGroupSession6.sessionKey();
assertFalse(sessionKey5.equals(sessionKey6));
assertNotEquals(sessionKey5, sessionKey6);
String sessionKey7 = outboundGroupSession7.sessionKey();
assertFalse(sessionKey6.equals(sessionKey7));
assertNotEquals(sessionKey6, sessionKey7);
String sessionKey8 = outboundGroupSession8.sessionKey();
assertFalse(sessionKey7.equals(sessionKey8));
assertNotEquals(sessionKey7, sessionKey8);
// get the session IDs from the outbound group sessions
String sessionId1 = outboundGroupSession1.sessionIdentifier();
String sessionId2 = outboundGroupSession2.sessionIdentifier();
assertFalse(sessionId1.equals(sessionId2));
assertNotEquals(sessionId1, sessionId2);
String sessionId3 = outboundGroupSession3.sessionKey();
assertFalse(sessionId2.equals(sessionId3));
assertNotEquals(sessionId2, sessionId3);
String sessionId4 = outboundGroupSession4.sessionKey();
assertFalse(sessionId3.equals(sessionId4));
assertNotEquals(sessionId3, sessionId4);
String sessionId5 = outboundGroupSession5.sessionKey();
assertFalse(sessionId4.equals(sessionId5));
assertNotEquals(sessionId4, sessionId5);
String sessionId6 = outboundGroupSession6.sessionKey();
assertFalse(sessionId5.equals(sessionId6));
assertNotEquals(sessionId5, sessionId6);
String sessionId7 = outboundGroupSession7.sessionKey();
assertFalse(sessionId6.equals(sessionId7));
assertNotEquals(sessionId6, sessionId7);
String sessionId8 = outboundGroupSession8.sessionKey();
assertFalse(sessionId7.equals(sessionId8));
assertNotEquals(sessionId7, sessionId8);