Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae78ffff authored by shamim-emon's avatar shamim-emon
Browse files

refactor(test): refactored SearchResponseTest

Replace junit assertion with AssertK assertion.

Adoption to new test guideline.
parent cd1366b8
Loading
Loading
Loading
Loading
+56 −11
Original line number Original line Diff line number Diff line
package com.fsck.k9.mail.store.imap
package com.fsck.k9.mail.store.imap


import assertk.all
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEmpty
import assertk.assertions.prop
import com.fsck.k9.mail.store.imap.SearchResponse.Companion.parse
import com.fsck.k9.mail.store.imap.SearchResponse.Companion.parse
import org.junit.Assert
import jdk.dynalink.linker.support.Guards.isNotNull
import kotlin.test.Test
import kotlin.test.Test
import org.junit.Assert


class SearchResponseTest {
class SearchResponseTest {
    @Test
    @Test
    fun parse_withSingleSearchResponse_shouldExtractNumbers() {
    fun parse_withSingleSearchResponse_shouldExtractNumbers() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList(
        val imapResponses = ImapResponseHelper.createImapResponseList(
            "* SEARCH 1 2 3",
            "* SEARCH 1 2 3",
            "* 23 EXISTS",
            "* 23 EXISTS",
@@ -14,14 +21,20 @@ class SearchResponseTest {
            "1 OK SEARCH completed",
            "1 OK SEARCH completed",
        )
        )


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        // Assert
        Assert.assertEquals(mutableListOf(1L, 2L, 3L, 4L), result.numbers)
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .containsExactly(1L, 2L, 3L, 4L)
        }
    }
    }


    @Test
    @Test
    fun parse_withMultipleSearchResponses_shouldExtractNumbers() {
    fun parse_withMultipleSearchResponses_shouldExtractNumbers() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList(
        val imapResponses = ImapResponseHelper.createImapResponseList(
            "* SEARCH 1 2 3",
            "* SEARCH 1 2 3",
            "* 23 EXISTS",
            "* 23 EXISTS",
@@ -35,49 +48,81 @@ class SearchResponseTest {
            "3 OK SEARCH completed",
            "3 OK SEARCH completed",
        )
        )


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        // Assert
        Assert.assertEquals(mutableListOf(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), result.numbers)
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .containsExactly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L)
        }
    }
    }


    @Test
    @Test
    fun parse_withSingleTaggedSearchResponse_shouldReturnEmptyList() {
    fun parse_withSingleTaggedSearchResponse_shouldReturnEmptyList() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList("x SEARCH 7 8 9")
        val imapResponses = ImapResponseHelper.createImapResponseList("x SEARCH 7 8 9")


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        Assert.assertNotNull(result)
        Assert.assertEquals(emptyList<Any>(), result.numbers)
        Assert.assertEquals(emptyList<Any>(), result.numbers)

        // Assert
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .isEmpty()
        }
    }
    }


    @Test
    @Test
    fun parse_withSingleTooShortResponse_shouldReturnEmptyList() {
    fun parse_withSingleTooShortResponse_shouldReturnEmptyList() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList("* SEARCH")
        val imapResponses = ImapResponseHelper.createImapResponseList("* SEARCH")


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        // Assert
        Assert.assertEquals(emptyList<Any>(), result.numbers)
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .isEmpty()
        }
    }
    }


    @Test
    @Test
    fun parse_withSingleNoSearchResponse_shouldReturnEmptyList() {
    fun parse_withSingleNoSearchResponse_shouldReturnEmptyList() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList("* 23 EXPUNGE")
        val imapResponses = ImapResponseHelper.createImapResponseList("* 23 EXPUNGE")


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        // Assert
        Assert.assertEquals(emptyList<Any>(), result.numbers)
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .isEmpty()
        }
    }
    }


    @Test
    @Test
    fun parse_withSingleSearchResponseContainingInvalidNumber_shouldReturnEmptyList() {
    fun parse_withSingleSearchResponseContainingInvalidNumber_shouldReturnEmptyList() {
        // Arrange
        val imapResponses = ImapResponseHelper.createImapResponseList("* SEARCH A")
        val imapResponses = ImapResponseHelper.createImapResponseList("* SEARCH A")


        // Act
        val result = parse(imapResponses)
        val result = parse(imapResponses)


        Assert.assertNotNull(result)
        // Assert
        Assert.assertEquals(emptyList<Any>(), result.numbers)
        assertThat(result).all {
            isNotNull()
            prop("numbers") { it.numbers }
                .isEmpty()
        }
    }
    }
}
}