Skip to content

Commit

Permalink
Added CreateMessageActivityWkdTest(not completed). Refactored code.| #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Aug 12, 2021
1 parent 3b75bd9 commit ac073eb
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import java.net.HttpURLConnection

/**
* @author Denis Bondarenko
Expand Down Expand Up @@ -78,12 +79,12 @@ class AttesterSettingsFragmentTest : BaseTest() {
if (request.path?.startsWith("/pub", ignoreCase = true) == true) {
val lastSegment = request.requestUrl?.pathSegments?.lastOrNull()
if (AccountDaoManager.getDefaultAccountDao().email.equals(lastSegment, true)) {
return MockResponse().setResponseCode(200)
return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(TestGeneralUtil.readResourceAsString("1.txt"))
}
}

return MockResponse().setResponseCode(404)
return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import org.junit.rules.TemporaryFolder
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import java.io.File
import java.net.HttpURLConnection
import java.time.Instant

/**
Expand Down Expand Up @@ -120,7 +121,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testEmptyRecipient() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()
onView(withId(R.id.editTextRecipientTo))
.check(matches(withText(isEmptyString())))
Expand All @@ -137,7 +138,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testEmptyEmailSubject() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand All @@ -163,7 +164,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testEmptyEmailMsg() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand All @@ -185,7 +186,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testUsingStandardMsgEncryptionType() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

if (defaultMsgEncryptionType != MessageEncryptionType.STANDARD) {
Expand All @@ -200,7 +201,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testUsingSecureMsgEncryptionType() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

if (defaultMsgEncryptionType != MessageEncryptionType.ENCRYPTED) {
Expand All @@ -214,7 +215,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSwitchBetweenEncryptionTypes() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

val messageEncryptionType = defaultMsgEncryptionType
Expand All @@ -238,12 +239,12 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testShowHelpScreen() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
}

@Test
fun testIsScreenOfComposeNewMsg() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withText(R.string.compose))
Expand All @@ -262,7 +263,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testWrongFormatOfRecipientEmailAddress() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

val invalidEmailAddresses = arrayOf("test", "test@", "test@@flowcrypt.test", "@flowcrypt.test")
Expand All @@ -285,7 +286,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testAddingAtts() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand All @@ -300,7 +301,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testMaxTotalAttachmentSize() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand Down Expand Up @@ -329,7 +330,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testDeletingAtts() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand All @@ -354,7 +355,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSelectImportPublicKeyFromPopUp() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()
intending(hasComponent(ComponentName(getTargetContext(), ImportPublicKeyActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
Expand Down Expand Up @@ -413,7 +414,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSelectedStandardEncryptionTypeFromPopUp() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

fillInAllFields(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER)
Expand All @@ -428,7 +429,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSelectedRemoveRecipientFromPopUp() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.layoutTo))
Expand Down Expand Up @@ -476,7 +477,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSelectedCopyFromOtherContactFromPopUp() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

fillInAllFields(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER)
Expand All @@ -495,7 +496,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

@Test
fun testSharePubKeySingle() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

openActionBarOverflowOrOptionsMenu(getTargetContext())
Expand All @@ -519,7 +520,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
)
val att = EmailUtil.genAttInfoFromPubKey(secondKeyDetails)

activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

openActionBarOverflowOrOptionsMenu(getTargetContext())
Expand Down Expand Up @@ -553,7 +554,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
TestConstants.DEFAULT_PASSWORD, KeyImportDetails.SourceType.EMAIL
)

activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

openActionBarOverflowOrOptionsMenu(getTargetContext())
Expand All @@ -575,7 +576,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
FlowCryptRoomDatabase.getDatabase(getTargetContext())
.contactsDao().insert(contact.toContactEntity())

activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

fillInAllFields(contact.email)
Expand Down Expand Up @@ -616,7 +617,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {

Assert.assertTrue(existedKeyExpiration.isBefore(Instant.now()))

activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

fillInAllFields(contact.email)
Expand Down Expand Up @@ -743,21 +744,21 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
lastSegment, true
) -> {
return MockResponse()
.setResponseCode(404)
.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
.setBody(TestGeneralUtil.readResourceAsString("2.txt"))
}

TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER.equals(
lastSegment, true
) -> {
return MockResponse()
.setResponseCode(200)
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(TestGeneralUtil.readResourceAsString("3.txt"))
}

"95FC072E853C9C333C68EDD34B9CA2FBCA5B5FE7".equals(lastSegment, true) -> {
return MockResponse()
.setResponseCode(200)
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
TestGeneralUtil.readFileFromAssetsAsString(
"pgp/[email protected]_not_expired_pub.asc"
Expand All @@ -767,7 +768,7 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
}
}

return MockResponse().setResponseCode(404)
return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import java.net.HttpURLConnection

/**
* @author Denis Bondarenko
Expand All @@ -58,7 +59,7 @@ class CreateMessageActivityTestPassInRamTest : BaseCreateMessageActivityTest() {

@Test
fun testShowingNeedPassphraseDialog() {
activeActivityRule.launch(intent)
activeActivityRule?.launch(intent)
registerAllIdlingResources()

fillInAllFields(TestConstants.RECIPIENT_WITH_PUBLIC_KEY_ON_ATTESTER)
Expand Down Expand Up @@ -102,13 +103,13 @@ class CreateMessageActivityTestPassInRamTest : BaseCreateMessageActivityTest() {
lastSegment, true
) -> {
return MockResponse()
.setResponseCode(200)
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(TestGeneralUtil.readResourceAsString("3.txt"))
}
}
}

return MockResponse().setResponseCode(404)
return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
}
})
}
Expand Down
Loading

0 comments on commit ac073eb

Please sign in to comment.