Skip to content

Commit

Permalink
Merge pull request thunderbird#6902 from thundernest/update_assertk
Browse files Browse the repository at this point in the history
Update assertk to version 0.26
  • Loading branch information
cketti authored May 17, 2023
2 parents d5f2345 + ef498c6 commit 517fffa
Show file tree
Hide file tree
Showing 33 changed files with 356 additions and 487 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fsck.k9

import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ConnectionSecurity
Expand Down Expand Up @@ -67,10 +67,9 @@ class ServerSettingsSerializerTest {
}
""".trimIndent()

assertThat {
assertFailure {
serverSettingsSerializer.deserialize(json)
}.isFailure()
.isInstanceOf(IllegalArgumentException::class)
}.isInstanceOf<IllegalArgumentException>()
.hasMessage("'type' must not be missing")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MessageHelperTest : RobolectricTest() {
changeContactNameColor = true,
contactNameColor = Color.RED,
)
assertThat(friendly).isInstanceOf(SpannableString::class.java)
assertThat(friendly).isInstanceOf<SpannableString>()
assertThat(friendly.toString()).isEqualTo("Tim Testor")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.fsck.k9.mailstore

import android.database.sqlite.SQLiteDatabase
import androidx.core.content.contentValuesOf
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasMessage
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import assertk.assertions.isTrue
import com.fsck.k9.Account
Expand Down Expand Up @@ -77,21 +77,19 @@ class K9BackendFolderTest : K9RobolectricTest() {
fun saveCompleteMessage_withoutServerId_shouldThrow() {
val message = createMessage(messageServerId = null)

assertThat {
assertFailure {
backendFolder.saveMessage(message, MessageDownloadState.FULL)
}.isFailure()
.isInstanceOf(IllegalStateException::class)
}.isInstanceOf<IllegalStateException>()
.hasMessage("Message requires a server ID to be set")
}

@Test
fun savePartialMessage_withoutServerId_shouldThrow() {
val message = createMessage(messageServerId = null)

assertThat {
assertFailure {
backendFolder.saveMessage(message, MessageDownloadState.PARTIAL)
}.isFailure()
.isInstanceOf(IllegalStateException::class)
}.isInstanceOf<IllegalStateException>()
.hasMessage("Message requires a server ID to be set")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class MimePartStreamParserTest {

val bodyPart = MimePartStreamParser.parse(null, ByteArrayInputStream(messageContent.toByteArray()))

assertThat(bodyPart.body).isInstanceOf(MimeMultipart::class).all {
assertThat(bodyPart.body).isInstanceOf<MimeMultipart>().all {
bodyParts().hasSize(2)
bodyPart(1).all {
mimeType().isEqualTo("message/rfc822")
body().isInstanceOf(MimeMessage::class)
body().isInstanceOf<MimeMessage>()
}
}
}
Expand Down Expand Up @@ -80,11 +80,11 @@ class MimePartStreamParserTest {

val bodyPart = MimePartStreamParser.parse(null, ByteArrayInputStream(messageContent.toByteArray()))

assertThat(bodyPart.body).isInstanceOf(MimeMultipart::class).all {
assertThat(bodyPart.body).isInstanceOf<MimeMultipart>().all {
bodyParts().hasSize(2)
bodyPart(1).all {
mimeType().isEqualTo("message/rfc822")
body().isInstanceOf(DeferredFileBody::class)
body().isInstanceOf<DeferredFileBody>()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fsck.k9.message.html

import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import assertk.assertions.prop
Expand Down Expand Up @@ -68,19 +68,17 @@ class GenericUriParserTest {

@Test
fun `negative 'startPos' value`() {
assertThat {
assertFailure {
parser.parseUri("test", -1)
}.isFailure()
.isInstanceOf(IllegalArgumentException::class)
}.isInstanceOf<IllegalArgumentException>()
.hasMessage("Invalid 'startPos' value")
}

@Test
fun `out of bounds 'startPos' value`() {
assertThat {
assertFailure {
parser.parseUri("test", 4)
}.isFailure()
.isInstanceOf(IllegalArgumentException::class)
}.isInstanceOf<IllegalArgumentException>()
.hasMessage("Invalid 'startPos' value")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fsck.k9.message.html

import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import assertk.assertions.isNull
Expand Down Expand Up @@ -287,19 +287,17 @@ class HttpUriParserTest {

@Test
fun `negative 'startPos' value`() {
assertThat {
assertFailure {
parser.parseUri("test", -1)
}.isFailure()
.isInstanceOf(IllegalArgumentException::class)
}.isInstanceOf<IllegalArgumentException>()
.hasMessage("Invalid 'startPos' value")
}

@Test
fun `out of bounds 'startPos' value`() {
assertThat {
assertFailure {
parser.parseUri("test", 4)
}.isFailure()
.isInstanceOf(IllegalArgumentException::class)
}.isInstanceOf<IllegalArgumentException>()
.hasMessage("Invalid 'startPos' value")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BaseNotificationDataCreatorTest {

val result = notificationDataCreator.createBaseNotificationData(notificationData)

assertThat(result.lockScreenNotificationData).isInstanceOf(LockScreenNotificationData.SenderNames::class.java)
assertThat(result.lockScreenNotificationData).isInstanceOf<LockScreenNotificationData.SenderNames>()
val senderNamesData = result.lockScreenNotificationData as LockScreenNotificationData.SenderNames
assertThat(senderNamesData.senderNames).isEqualTo("Sender One, Sender Two, Sender Three")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class NewMailNotificationManagerTest {
summary = "summary",
),
)
assertThat(result.summaryNotificationData).isNotNull().isInstanceOf(SummarySingleNotificationData::class.java)
assertThat(result.summaryNotificationData).isNotNull().isInstanceOf<SummarySingleNotificationData>()
val summaryNotificationData = result.summaryNotificationData as SummarySingleNotificationData
assertThat(summaryNotificationData.singleNotificationData.isSilent).isFalse()
}
Expand Down Expand Up @@ -108,7 +108,7 @@ class NewMailNotificationManagerTest {
),
)
assertThat(result.baseNotificationData.newMessagesCount).isEqualTo(2)
assertThat(result.summaryNotificationData).isNotNull().isInstanceOf(SummaryInboxNotificationData::class.java)
assertThat(result.summaryNotificationData).isNotNull().isInstanceOf<SummaryInboxNotificationData>()
val summaryNotificationData = result.summaryNotificationData as SummaryInboxNotificationData
assertThat(summaryNotificationData.content).isEqualTo(listOf("Zoe Meeting", "Alice Hi Bob"))
assertThat(summaryNotificationData.messageReferences).isEqualTo(
Expand Down Expand Up @@ -229,7 +229,7 @@ class NewMailNotificationManagerTest {
assertThat(data.cancelNotificationIds).isEqualTo(listOf(notificationIdTwo))
assertThat(data.singleNotificationData).isEmpty()
assertThat(data.baseNotificationData.newMessagesCount).isEqualTo(2)
assertThat(data.summaryNotificationData).isNotNull().isInstanceOf(SummaryInboxNotificationData::class.java)
assertThat(data.summaryNotificationData).isNotNull().isInstanceOf<SummaryInboxNotificationData>()
val summaryNotificationData = data.summaryNotificationData as SummaryInboxNotificationData
assertThat(summaryNotificationData.content).isEqualTo(listOf("Alice Three", "Alice One"))
assertThat(summaryNotificationData.messageReferences).isEqualTo(
Expand Down Expand Up @@ -317,7 +317,7 @@ class NewMailNotificationManagerTest {
),
)

assertThat(data.summaryNotificationData).isNotNull().isInstanceOf(SummarySingleNotificationData::class.java)
assertThat(data.summaryNotificationData).isNotNull().isInstanceOf<SummarySingleNotificationData>()
val summaryNotificationData = data.summaryNotificationData as SummarySingleNotificationData
assertThat(summaryNotificationData.singleNotificationData.isSilent).isTrue()
assertThat(summaryNotificationData.singleNotificationData.content).isEqualTo(
Expand Down Expand Up @@ -354,7 +354,7 @@ class NewMailNotificationManagerTest {
assertThat(data.singleNotificationData).hasSize(MAX_NUMBER_OF_NEW_MESSAGE_NOTIFICATIONS)
assertThat(data.singleNotificationData.map { it.content.sender }).doesNotContain("inactive")

assertThat(data.summaryNotificationData).isNotNull().isInstanceOf(SummaryInboxNotificationData::class.java)
assertThat(data.summaryNotificationData).isNotNull().isInstanceOf<SummaryInboxNotificationData>()
val summaryNotificationData = data.summaryNotificationData as SummaryInboxNotificationData
assertThat(summaryNotificationData.isSilent).isTrue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class NotificationDataStoreTest : RobolectricTest() {
assertThat(removeResult.notificationHolders).hasSize(0)
assertThat(removeResult.notificationStoreOperations).hasSize(MAX_NUMBER_OF_NEW_MESSAGE_NOTIFICATIONS + 1)
for (notificationStoreOperation in removeResult.notificationStoreOperations) {
assertThat(notificationStoreOperation).isInstanceOf(NotificationStoreOperation.Remove::class.java)
assertThat(notificationStoreOperation).isInstanceOf<NotificationStoreOperation.Remove>()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SummaryNotificationDataCreatorTest {
silent = false,
)

assertThat(result).isInstanceOf(SummarySingleNotificationData::class.java)
assertThat(result).isInstanceOf<SummarySingleNotificationData>()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.fsck.k9.preferences

import android.content.Context
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.containsOnly
import assertk.assertions.isEmpty
import assertk.assertions.isFailure
import assertk.assertions.isSameAs
import assertk.assertions.isTrue
import com.fsck.k9.preferences.K9StoragePersister.StoragePersistOperationCallback
Expand Down Expand Up @@ -63,10 +63,9 @@ class StoragePersisterTest : K9RobolectricTest() {
},
)

assertThat {
assertFailure {
storagePersister.doInTransaction(operationCallback)
}.isFailure()
.isSameAs(exception)
}.isSameAs(exception)

val values = storagePersister.loadValues()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fsck.k9.storage.messages

import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import assertk.assertions.isNotNull
import assertk.assertions.isNull
Expand Down Expand Up @@ -482,10 +482,9 @@ class RetrieveFolderOperationsTest : RobolectricTest() {

@Test
fun `get 'more messages' value from non-existent folder`() {
assertThat {
assertFailure {
retrieveFolderOperations.hasMoreMessages(23)
}.isFailure()
.isInstanceOf(FolderNotFoundException::class)
}.isInstanceOf<FolderNotFoundException>()
.transform { it.folderId }.isEqualTo(23)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ class PgpMessageBuilderTest : K9RobolectricTest() {
val message = captor.value
assertThat(message.mimeType).isEqualTo("multipart/signed")

assertThat(message.body).isInstanceOf(MimeMultipart::class).all {
assertThat(message.body).isInstanceOf<MimeMultipart>().all {
bodyParts().hasSize(2)
bodyPart(0).all {
contentType().value().isEqualTo("text/plain")
body().isInstanceOf(TextBody::class).all {
body().isInstanceOf<TextBody>().all {
contentTransferEncoding().isEqualTo(MimeUtil.ENC_QUOTED_PRINTABLE)
asText().isEqualTo(TEST_MESSAGE_TEXT)
}
Expand Down Expand Up @@ -559,7 +559,7 @@ class PgpMessageBuilderTest : K9RobolectricTest() {

assertThat(message).all {
mimeType().isEqualTo("multipart/encrypted")
body().isInstanceOf(MimeMultipart::class).all {
body().isInstanceOf<MimeMultipart>().all {
bodyParts().hasSize(2)
bodyPart(0).all {
contentType().value().isEqualTo("application/pgp-encrypted")
Expand All @@ -570,7 +570,7 @@ class PgpMessageBuilderTest : K9RobolectricTest() {
value().isEqualTo("application/octet-stream")
parameter("name").isEqualTo("encrypted.asc")
}
body().isInstanceOf(BinaryTempFileBody::class)
body().isInstanceOf<BinaryTempFileBody>()
.contentTransferEncoding().isEqualTo(MimeUtil.ENC_7BIT)
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ class PgpMessageBuilderTest : K9RobolectricTest() {
val message = captor.value
assertThat(message).all {
mimeType().isEqualTo("text/plain")
body().isInstanceOf(BinaryTempFileBody::class)
body().isInstanceOf<BinaryTempFileBody>()
.contentTransferEncoding().isEqualTo(MimeUtil.ENC_7BIT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class MessageDetailsParticipantFormatterTest : RobolectricTest() {
val displayName = participantFormatter.getDisplayName(Address("user1@domain.example"), account)

assertThat(displayName.toString()).isEqualTo("Contact One")
assertThat(displayName).isNotNull().isInstanceOf(Spannable::class.java)
assertThat(displayName).isNotNull().isInstanceOf<Spannable>()
val spans = (displayName as Spannable).getSpans<ForegroundColorSpan>(0, displayName.length)
assertThat(spans.map { it.foregroundColor }).containsExactly(Color.RED)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class MessageViewRecipientFormatterTest : RobolectricTest() {
val displayName = recipientFormatter.getDisplayName(Address("user1@domain.example"), account)

assertThat(displayName.toString()).isEqualTo("Contact One")
assertThat(displayName).isInstanceOf(Spannable::class.java)
assertThat(displayName).isInstanceOf<Spannable>()
val spans = (displayName as Spannable).getSpans<ForegroundColorSpan>(0, displayName.length)
assertThat(spans.map { it.foregroundColor }).containsExactly(Color.RED)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fsck.k9.backend.jmap

import app.k9mail.backend.testing.InMemoryBackendStorage
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.containsExactlyInAnyOrder
import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import assertk.assertions.isTrue
import assertk.fail
Expand All @@ -28,10 +28,9 @@ class CommandRefreshFolderListTest {
MockResponse().setResponseCode(401),
)

assertThat {
assertFailure {
command.refreshFolderList()
}.isFailure()
.isInstanceOf(AuthenticationFailedException::class)
}.isInstanceOf<AuthenticationFailedException>()
}

@Test
Expand All @@ -40,10 +39,9 @@ class CommandRefreshFolderListTest {
MockResponse().setBody("invalid"),
)

assertThat {
assertFailure {
command.refreshFolderList()
}.isFailure()
.isInstanceOf(MessagingException::class)
}.isInstanceOf<MessagingException>()
.transform { it.isPermanentFailure }.isTrue()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CommandSyncTest {

assertThat(syncListener.getNextEvent()).isEqualTo(SyncListenerEvent.SyncStarted(FOLDER_SERVER_ID))
val failedEvent = syncListener.getNextEvent() as SyncListenerEvent.SyncFailed
assertThat(failedEvent.exception).isNotNull().isInstanceOf(AuthenticationFailedException::class)
assertThat(failedEvent.exception).isNotNull().isInstanceOf<AuthenticationFailedException>()
}

@Test
Expand Down
Loading

0 comments on commit 517fffa

Please sign in to comment.