Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTV-492 :Deprecate Autoparcel for EmailVerificationEnvelope.kt (#1597)
* NTV-492 Deprecate Autoparcel for EmailVerificationEnvelope.kt * Fix ktlint
- Loading branch information
Showing
2 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
52 changes: 31 additions & 21 deletions
52
app/src/main/java/com/kickstarter/services/apiresponses/EmailVerificationEnvelope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
package com.kickstarter.services.apiresponses | ||
|
||
import android.os.Parcelable | ||
import auto.parcel.AutoParcel | ||
import com.kickstarter.libs.qualifiers.AutoGson | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@AutoGson | ||
@AutoParcel | ||
abstract class EmailVerificationEnvelope : Parcelable { | ||
abstract fun message(): String | ||
abstract fun code(): Int | ||
@Parcelize | ||
class EmailVerificationEnvelope private constructor( | ||
private val message: String, | ||
private val code: Int | ||
) : Parcelable { | ||
fun message() = this.message | ||
fun code() = this.code | ||
|
||
@AutoParcel.Builder | ||
abstract class Builder { | ||
abstract fun message(message: String): Builder | ||
abstract fun code(code: Int): Builder | ||
abstract fun build(): EmailVerificationEnvelope | ||
@Parcelize | ||
data class Builder( | ||
private var message: String = "", | ||
private var code: Int = 0 | ||
) : Parcelable { | ||
fun message(message: String) = apply { this.message = message } | ||
fun code(code: Int) = apply { this.code = code } | ||
fun build() = EmailVerificationEnvelope( | ||
message = message, | ||
code = code | ||
) | ||
} | ||
|
||
@Override | ||
fun toBuilder() = Builder( | ||
message = message, | ||
code = code | ||
) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
return if (other is EmailVerificationEnvelope) { | ||
other.code() == this.code() && other.message() == this.message() | ||
} else super.equals(other) | ||
var equals = super.equals(other) | ||
if (other is EmailVerificationEnvelope) { | ||
equals = other.code() == this.code() && other.message() == this.message() | ||
} | ||
return equals | ||
} | ||
|
||
abstract fun toBuilder(): Builder | ||
|
||
companion object { | ||
fun builder(): Builder { | ||
return AutoParcel_EmailVerificationEnvelope.Builder() | ||
} | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/src/test/java/com/kickstarter/models/EmailVerificationEnvelopeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.kickstarter.models | ||
|
||
import com.kickstarter.services.apiresponses.EmailVerificationEnvelope | ||
import junit.framework.TestCase | ||
import org.junit.Test | ||
|
||
class EmailVerificationEnvelopeTest : TestCase() { | ||
|
||
@Test | ||
fun testDefaultInit() { | ||
val message = "test" | ||
|
||
val emailVerificationEnvelope = EmailVerificationEnvelope.builder() | ||
.message(message) | ||
.code(1) | ||
.build() | ||
|
||
assertEquals(emailVerificationEnvelope.message(), message) | ||
|
||
assertEquals(emailVerificationEnvelope.code(), 1) | ||
} | ||
|
||
@Test | ||
fun testEmailVerificationEnvelope_equalFalse() { | ||
val message = "test" | ||
val emailVerificationEnvelope = EmailVerificationEnvelope.builder().build() | ||
val emailVerificationEnvelope2 = | ||
EmailVerificationEnvelope.builder().message(message).build() | ||
val emailVerificationEnvelope3 = EmailVerificationEnvelope.builder().code(3).build() | ||
|
||
assertFalse(emailVerificationEnvelope == emailVerificationEnvelope2) | ||
assertFalse(emailVerificationEnvelope == emailVerificationEnvelope3) | ||
|
||
assertFalse(emailVerificationEnvelope3 == emailVerificationEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testEmailVerificationEnvelope_equalTrue() { | ||
val emailVerificationEnvelope1 = EmailVerificationEnvelope.builder().build() | ||
val emailVerificationEnvelope2 = EmailVerificationEnvelope.builder().build() | ||
|
||
assertEquals(emailVerificationEnvelope1, emailVerificationEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testEmailVerificationEnvelopeToBuilder() { | ||
val message = "test" | ||
val emailVerificationEnvelope = EmailVerificationEnvelope.builder().build().toBuilder() | ||
.message(message).build() | ||
|
||
assertEquals(emailVerificationEnvelope.message(), message) | ||
} | ||
} |