Add responseText
property to NegativeImapResponseException
This commit is contained in:
parent
3abe666bd3
commit
8143ae53ec
3 changed files with 82 additions and 2 deletions
|
@ -14,6 +14,8 @@ internal class NegativeImapResponseException(
|
|||
val lastResponse: ImapResponse
|
||||
get() = responses.last()
|
||||
|
||||
val responseText: String? by lazy { ResponseTextExtractor.getResponseText(lastResponse) }
|
||||
|
||||
val alertText: String? by lazy { AlertResponse.getAlertText(lastResponse) }
|
||||
|
||||
fun wasByeResponseReceived(): Boolean {
|
||||
|
|
|
@ -363,7 +363,7 @@ internal class RealImapConnection(
|
|||
return AuthenticationFailedException(
|
||||
message = "Authentication failed",
|
||||
throwable = e,
|
||||
messageFromServer = ResponseTextExtractor.getResponseText(e.lastResponse),
|
||||
messageFromServer = e.responseText,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,7 @@ internal class RealImapConnection(
|
|||
AuthenticationFailedException(
|
||||
message = "Authentication failed",
|
||||
throwable = negativeResponseException,
|
||||
messageFromServer = ResponseTextExtractor.getResponseText(lastResponse),
|
||||
messageFromServer = negativeResponseException.responseText,
|
||||
)
|
||||
} else {
|
||||
close()
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package com.fsck.k9.mail.store.imap
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFalse
|
||||
import assertk.assertions.isNull
|
||||
import assertk.assertions.isTrue
|
||||
import com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponseList
|
||||
import kotlin.test.Test
|
||||
|
||||
class NegativeImapResponseExceptionTest {
|
||||
@Test
|
||||
fun `responseText property should contain response text of last response`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList("x NO [AUTHENTICATIONFAILED] Authentication error #23"),
|
||||
)
|
||||
|
||||
assertThat(exception.responseText).isEqualTo("Authentication error #23")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `responseText property should be null when last response does not contain response text`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList("x NO"),
|
||||
)
|
||||
|
||||
assertThat(exception.responseText).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `alertText property should contain alert text of last response`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList("x NO [ALERT] Service is shutting down"),
|
||||
)
|
||||
|
||||
assertThat(exception.alertText).isEqualTo("Service is shutting down")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `alertText property should be null when last response does not contain alert text`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList("x NO Not allowed"),
|
||||
)
|
||||
|
||||
assertThat(exception.alertText).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `wasByeResponseReceived() should return true when BYE response was received`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList(
|
||||
"* EXISTS 1",
|
||||
"* BYE",
|
||||
"x OK",
|
||||
),
|
||||
)
|
||||
|
||||
assertThat(exception.wasByeResponseReceived()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `wasByeResponseReceived() should return false when no BYE response was received`() {
|
||||
val exception = NegativeImapResponseException(
|
||||
message = "Test",
|
||||
responses = createImapResponseList(
|
||||
"* EXISTS 1",
|
||||
"x OK",
|
||||
),
|
||||
)
|
||||
|
||||
assertThat(exception.wasByeResponseReceived()).isFalse()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue