Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate kt tests off hamcrest #13888

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
65816d3
PaddingInputStreamTest Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
c7b99c8
SecondaryProvisioningCipherTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
23e890f
PushChallengeRequestTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
235396a
NotificationProfilesTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
a74885a
CallParticipantListUpdateTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
f40f66f
SmsDatabaseTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
ded229c
GroupManagerV2Test_edit, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
e5c6d25
DeviceNameCipherTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
c41586c
RemoteMegaphoneRepositoryTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
b814b86
NotificationProfileScheduleTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
3d8695f
GroupsV2StateProcessorTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
e99bbef
Readability improvements GroupsV2StateProcessorTest
jamesonwilliams Jan 8, 2025
06f1fcd
MentionUtilTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
3733603
NotificationProfileTablesTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
da737cf
Remove uses of KotlinAssertUtil (implemented via Hamcrest)
jamesonwilliams Jan 8, 2025
cd65772
SmsDatabaseTest_collapseJoinRequestEventsIfPossible, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
b30bb35
RecipientTableTest_getAndPossiblyMerge, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
3c41fc4
InAppPaymentAuthCheckJobTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
8bb98d5
SyncMessageProcessorTest_synchronizeDeleteForMe, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
6a7e5b4
StorySendTableTest, Hamcrest -> AssertK
jamesonwilliams Jan 8, 2025
01a990a
Remove Hamcrest based TestUtils functions
jamesonwilliams Jan 8, 2025
acb8562
Formatting
jamesonwilliams Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ dependencies {
androidTestImplementation(testLibs.androidx.test.core)
androidTestImplementation(testLibs.androidx.test.core.ktx)
androidTestImplementation(testLibs.androidx.test.ext.junit.ktx)
androidTestImplementation(testLibs.assertk)
androidTestImplementation(testLibs.mockk.android)
androidTestImplementation(testLibs.square.okhttp.mockserver)
androidTestImplementation(testLibs.diff.utils)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.net.Uri
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEqualTo
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
Expand All @@ -22,8 +25,6 @@ import org.thoughtcrime.securesms.attachments.UriAttachment
import org.thoughtcrime.securesms.mms.MediaStream
import org.thoughtcrime.securesms.mms.SentMediaQuality
import org.thoughtcrime.securesms.providers.BlobProvider
import org.thoughtcrime.securesms.testing.assertIs
import org.thoughtcrime.securesms.testing.assertIsNot
import org.thoughtcrime.securesms.util.MediaUtil
import org.thoughtcrime.securesms.util.Util
import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream
Expand Down Expand Up @@ -142,8 +143,8 @@ class AttachmentTableTest {
val highInfo = SignalDatabase.attachments.getDataFileInfo(highDatabaseAttachment.attachmentId)!!

assertNotEquals(standardInfo, highInfo)
highInfo.file assertIsNot standardInfo.file
highInfo.file.exists() assertIs true
assertThat(highInfo.file).isNotEqualTo(standardInfo.file)
assertThat(highInfo.file.exists()).isEqualTo(true)
}

/**
Expand Down Expand Up @@ -174,10 +175,10 @@ class AttachmentTableTest {
val highInfo = SignalDatabase.attachments.getDataFileInfo(highDatabaseAttachment.attachmentId)!!
val secondHighInfo = SignalDatabase.attachments.getDataFileInfo(secondHighDatabaseAttachment.attachmentId)!!

highInfo.file assertIsNot standardInfo.file
secondHighInfo.file assertIs highInfo.file
standardInfo.file.exists() assertIs true
highInfo.file.exists() assertIs true
assertThat(highInfo.file).isNotEqualTo(standardInfo.file)
assertThat(secondHighInfo.file).isEqualTo(highInfo.file)
assertThat(standardInfo.file.exists()).isEqualTo(true)
assertThat(highInfo.file.exists()).isEqualTo(true)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.thoughtcrime.securesms.database

import androidx.test.ext.junit.runners.AndroidJUnit4
import assertk.assertThat
import assertk.assertions.isEqualTo
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.signal.core.util.count
import org.signal.core.util.readToSingleInt
import org.thoughtcrime.securesms.backup.v2.ArchivedMediaObject
import org.thoughtcrime.securesms.testing.SignalActivityRule
import org.thoughtcrime.securesms.testing.assertIs

@RunWith(AndroidJUnit4::class)
class BackupMediaSnapshotTableTest {
Expand All @@ -27,7 +28,7 @@ class BackupMediaSnapshotTableTest {

val count = getSyncedItemCount(pendingSyncTime)

count.assertIs(0)
assertThat(count).isEqualTo(0)
}

@Test
Expand All @@ -38,7 +39,7 @@ class BackupMediaSnapshotTableTest {

val count = getSyncedItemCount(pendingSyncTime)

count.assertIs(SEQUENCE_COUNT)
assertThat(count).isEqualTo(SEQUENCE_COUNT)
}

@Test
Expand All @@ -56,7 +57,7 @@ class BackupMediaSnapshotTableTest {
.run()
.readToSingleInt(-1)

count.assertIs(50)
assertThat(count).isEqualTo(50)
}

@Test
Expand All @@ -77,8 +78,8 @@ class BackupMediaSnapshotTableTest {

val total = getTotalItemCount()

count.assertIs(50)
total.assertIs(SEQUENCE_COUNT)
assertThat(count).isEqualTo(50)
assertThat(total).isEqualTo(SEQUENCE_COUNT)
}

@Test
Expand All @@ -96,7 +97,7 @@ class BackupMediaSnapshotTableTest {

val total = getTotalItemCount()

total.assertIs(50)
assertThat(total).isEqualTo(50)
}

private fun getTotalItemCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.thoughtcrime.securesms.database

import android.database.sqlite.SQLiteConstraintException
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNull
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
Expand All @@ -12,7 +15,6 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaym
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData
import org.thoughtcrime.securesms.testing.SignalActivityRule
import org.thoughtcrime.securesms.testing.assertIs
import org.whispersystems.signalservice.api.storage.IAPSubscriptionId
import org.whispersystems.signalservice.api.subscriptions.SubscriberId
import java.util.Currency
Expand Down Expand Up @@ -191,11 +193,11 @@ class InAppPaymentSubscriberTableTest {
.run()
.readToSingleInt()

subscriberCount assertIs 1
assertThat(subscriberCount).isEqualTo(1)

val subscriber = InAppPaymentsRepository.requireSubscriber(InAppPaymentSubscriberRecord.Type.BACKUP)
subscriber.iapSubscriptionId?.originalTransactionId assertIs null
subscriber.iapSubscriptionId?.purchaseToken assertIs "testToken"
subscriber.subscriberId assertIs googleSubscriber.subscriberId
assertThat(subscriber.iapSubscriptionId?.originalTransactionId).isNull()
assertThat(subscriber.iapSubscriptionId?.purchaseToken).isEqualTo("testToken")
assertThat(subscriber.subscriberId).isEqualTo(googleSubscriber.subscriberId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.thoughtcrime.securesms.database

import androidx.test.ext.junit.runners.AndroidJUnit4
import assertk.assertThat
import assertk.assertions.isEqualTo
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -14,7 +16,6 @@ import org.signal.core.util.deleteAll
import org.signal.donations.InAppPaymentType
import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData
import org.thoughtcrime.securesms.testing.SignalActivityRule
import org.thoughtcrime.securesms.testing.assertIs

@RunWith(AndroidJUnit4::class)
class InAppPaymentTableTest {
Expand All @@ -37,13 +38,13 @@ class InAppPaymentTableTest {
)

val paymentBeforeUpdate = SignalDatabase.inAppPayments.getById(inAppPaymentId)
paymentBeforeUpdate?.state assertIs InAppPaymentTable.State.CREATED
assertThat(paymentBeforeUpdate?.state).isEqualTo(InAppPaymentTable.State.CREATED)

SignalDatabase.inAppPayments.update(
inAppPayment = paymentBeforeUpdate!!.copy(state = InAppPaymentTable.State.PENDING)
)

val paymentAfterUpdate = SignalDatabase.inAppPayments.getById(inAppPaymentId)
paymentAfterUpdate?.state assertIs InAppPaymentTable.State.PENDING
assertThat(paymentAfterUpdate?.state).isEqualTo(InAppPaymentTable.State.PENDING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

package org.thoughtcrime.securesms.database

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isTrue
import org.junit.Test
import org.signal.core.util.forEach
import org.signal.core.util.requireLong
Expand All @@ -13,7 +17,6 @@ import org.signal.core.util.select
import org.signal.core.util.updateAll
import org.thoughtcrime.securesms.crash.CrashConfig
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.testing.assertIs

class LogDatabaseTest {

Expand All @@ -37,7 +40,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -58,7 +61,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -79,7 +82,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -100,7 +103,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -121,7 +124,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -142,7 +145,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs true
assertThat(foundMatch).isTrue()
}

@Test
Expand All @@ -163,7 +166,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs false
assertThat(foundMatch).isFalse()
}

@Test
Expand All @@ -184,7 +187,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs false
assertThat(foundMatch).isFalse()
}

@Test
Expand All @@ -205,7 +208,7 @@ class LogDatabaseTest {
promptThreshold = currentTime
)

foundMatch assertIs false
assertThat(foundMatch).isFalse()
}

@Test
Expand All @@ -231,7 +234,7 @@ class LogDatabaseTest {
promptThreshold = currentTime - 100
)

foundMatch assertIs false
assertThat(foundMatch).isFalse()
}

@Test
Expand All @@ -245,7 +248,7 @@ class LogDatabaseTest {
promptThreshold = currentTime - 100
)

foundMatch assertIs false
assertThat(foundMatch).isFalse()
}

@Test
Expand Down Expand Up @@ -279,9 +282,9 @@ class LogDatabaseTest {
.run()
.forEach {
if (it.requireNonNullString(LogDatabase.CrashTable.NAME) == "TestName") {
it.requireLong(LogDatabase.CrashTable.LAST_PROMPTED_AT) assertIs currentTime
assertThat(it.requireLong(LogDatabase.CrashTable.LAST_PROMPTED_AT)).isEqualTo(currentTime)
} else {
it.requireLong(LogDatabase.CrashTable.LAST_PROMPTED_AT) assertIs 0
assertThat(it.requireLong(LogDatabase.CrashTable.LAST_PROMPTED_AT)).isEqualTo(0)
}
}
}
Expand Down
Loading