Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTV-438: Deprecate autoparcel for checkout (#1583)
* NTV-438 Deprecate Autoparcel for Checkout.kt * update test * update SurveyResponse * update Ktlint
- Loading branch information
Showing
5 changed files
with
137 additions
and
46 deletions.
There are no files selected for viewing
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
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
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,49 +1,87 @@ | ||
package com.kickstarter.models | ||
|
||
import android.os.Parcelable | ||
import auto.parcel.AutoParcel | ||
|
||
@AutoParcel | ||
abstract class Checkout : Parcelable { | ||
abstract fun id(): Long? | ||
abstract fun backing(): Backing | ||
|
||
@AutoParcel.Builder | ||
abstract class Builder { | ||
abstract fun id(id: Long?): Builder | ||
abstract fun backing(backing: Backing): Builder | ||
abstract fun build(): Checkout | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
class Checkout private constructor( | ||
private val id: Long?, | ||
private val backing: Backing, | ||
) : Parcelable { | ||
fun id() = this.id | ||
fun backing() = this.backing | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var id: Long? = null, | ||
private var backing: Backing = Backing.builder().build() | ||
) : Parcelable { | ||
fun id(id: Long?) = apply { this.id = id } | ||
fun backing(backing: Backing) = apply { this.backing = backing } | ||
fun build() = Checkout( | ||
id = id, | ||
backing = backing | ||
) | ||
} | ||
|
||
abstract fun toBuilder(): Builder | ||
fun toBuilder() = Builder( | ||
id = id, | ||
backing = backing | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
fun builder(): Builder { | ||
return AutoParcel_Checkout.Builder() | ||
override fun equals(obj: Any?): Boolean { | ||
var equals = super.equals(obj) | ||
if (obj is Checkout) { | ||
equals = id() == obj.id() && | ||
backing() == obj.backing() | ||
} | ||
return equals | ||
} | ||
|
||
@AutoParcel | ||
abstract class Backing : Parcelable { | ||
@Parcelize | ||
data class Backing private constructor( | ||
private val clientSecret: String?, | ||
private val requiresAction: Boolean, | ||
) : Parcelable { | ||
|
||
fun clientSecret() = this.clientSecret | ||
fun requiresAction() = this.requiresAction | ||
|
||
abstract fun clientSecret(): String? | ||
abstract fun requiresAction(): Boolean | ||
@Parcelize | ||
data class Builder( | ||
private var clientSecret: String? = null, | ||
private var requiresAction: Boolean = false, | ||
) : Parcelable { | ||
fun clientSecret(clientSecret: String?) = apply { this.clientSecret = clientSecret } | ||
fun requiresAction(requiresAction: Boolean) = apply { this.requiresAction = requiresAction } | ||
fun build() = Backing( | ||
clientSecret = clientSecret, | ||
requiresAction = requiresAction | ||
) | ||
} | ||
|
||
@AutoParcel.Builder | ||
abstract class Builder { | ||
abstract fun clientSecret(secret: String?): Builder | ||
abstract fun requiresAction(requiresAction: Boolean): Builder | ||
abstract fun build(): Backing | ||
override fun equals(obj: Any?): Boolean { | ||
var equals = super.equals(obj) | ||
if (obj is Backing) { | ||
equals = clientSecret() == obj.clientSecret() && | ||
requiresAction() == obj.requiresAction() | ||
} | ||
return equals | ||
} | ||
fun toBuilder() = Builder( | ||
clientSecret = clientSecret, | ||
requiresAction = requiresAction | ||
|
||
abstract fun toBuilder(): Builder | ||
) | ||
|
||
companion object { | ||
|
||
fun builder(): Builder { | ||
return AutoParcel_Checkout_Backing.Builder() | ||
} | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
} | ||
} |
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
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,55 @@ | ||
package com.kickstarter.models | ||
|
||
import com.kickstarter.KSRobolectricTestCase | ||
import com.kickstarter.mock.factories.CheckoutBackingFactory | ||
import com.kickstarter.mock.factories.CheckoutFactory | ||
import org.junit.Test | ||
|
||
class CheckoutTest : KSRobolectricTestCase() { | ||
|
||
@Test | ||
fun testDefaultInit() { | ||
val backing = Checkout.Backing.builder() | ||
.requiresAction(true) | ||
.build() | ||
|
||
val checkout = Checkout.builder() | ||
.id(1234L) | ||
.backing(backing) | ||
.build() | ||
|
||
assertEquals(checkout.id(), 1234L) | ||
assertEquals(checkout.backing(), backing) | ||
assertEquals(backing.requiresAction(), true) | ||
assertEquals(backing.clientSecret(), null) | ||
} | ||
|
||
@Test | ||
fun testDefaultWebInit() { | ||
|
||
val backing = Checkout.Backing.builder().build().toBuilder().requiresAction(false).build() | ||
assertFalse(backing.requiresAction()) | ||
|
||
val checkout = Checkout.builder().build().toBuilder().backing(backing).build() | ||
assertEquals(checkout.backing(), backing) | ||
} | ||
|
||
@Test | ||
fun testCheckout_equalFalse() { | ||
val checkout = CheckoutFactory.requiresAction(false) | ||
val checkout2 = Checkout.builder().backing(CheckoutBackingFactory.requiresAction(true)).build() | ||
val checkout3 = Checkout.builder().id(5678L).build() | ||
|
||
assertFalse(checkout == checkout2) | ||
assertFalse(checkout == checkout3) | ||
assertFalse(checkout3 == checkout2) | ||
} | ||
|
||
@Test | ||
fun testCheckout_equalTrue() { | ||
val checkout1 = Checkout.builder().build() | ||
val checkout2 = Checkout.builder().build() | ||
|
||
assertEquals(checkout1, checkout2) | ||
} | ||
} |