-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTV-480: Migrate InternalBuildEnvelope.java to kotlin and deprecate A…
…utoparcel (#1612) * Mograte to kotlin, deprecate autoparcel, tests * Linter Co-authored-by: Isabel Martin <[email protected]> Co-authored-by: Hadia <[email protected]>
- Loading branch information
1 parent
4b8ce8c
commit cd5d8a8
Showing
5 changed files
with
143 additions
and
52 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
app/src/main/java/com/kickstarter/mock/factories/InternalBuildEnvelopeFactory.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/kickstarter/mock/factories/InternalBuildEnvelopeFactory.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,20 @@ | ||
package com.kickstarter.mock.factories | ||
|
||
import com.kickstarter.services.apiresponses.InternalBuildEnvelope | ||
|
||
object InternalBuildEnvelopeFactory { | ||
fun internalBuildEnvelope(): InternalBuildEnvelope { | ||
return InternalBuildEnvelope.builder() | ||
.build(123456) | ||
.changelog("Bug fixes") | ||
.newerBuildAvailable(false) | ||
.build() | ||
} | ||
|
||
@JvmStatic | ||
fun newerBuildAvailable(): InternalBuildEnvelope { | ||
return internalBuildEnvelope().toBuilder() | ||
.newerBuildAvailable(true) | ||
.build() | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/kickstarter/services/apiresponses/InternalBuildEnvelope.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/kickstarter/services/apiresponses/InternalBuildEnvelope.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.services.apiresponses | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
class InternalBuildEnvelope private constructor( | ||
private val build: Int?, | ||
private val changelog: String?, | ||
private val newerBuildAvailable: Boolean | ||
) : Parcelable { | ||
fun build() = this.build | ||
fun changelog() = this.changelog | ||
fun newerBuildAvailable() = this.newerBuildAvailable | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var build: Int? = null, | ||
private var changelog: String? = null, | ||
private var newerBuildAvailable: Boolean = false | ||
) : Parcelable { | ||
fun build(build: Int?) = apply { this.build = build ?: 0 } | ||
fun changelog(changelog: String?) = apply { this.changelog = changelog ?: "" } | ||
fun newerBuildAvailable(newerBuildAvailable: Boolean?) = apply { this.newerBuildAvailable = newerBuildAvailable ?: false } | ||
fun build() = InternalBuildEnvelope( | ||
build = build, | ||
changelog = changelog, | ||
newerBuildAvailable = newerBuildAvailable | ||
) | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
build = build, | ||
changelog = changelog, | ||
newerBuildAvailable = newerBuildAvailable | ||
) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
var equals = super.equals(other) | ||
if (other is InternalBuildEnvelope) { | ||
equals = build() == other.build() && | ||
changelog() == other.changelog() && | ||
newerBuildAvailable() == other.newerBuildAvailable() | ||
} | ||
return equals | ||
} | ||
|
||
companion object { | ||
fun builder(): Builder { | ||
return Builder() | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
app/src/test/java/com/kickstarter/services/apiresponses/InternalBuildEnvelopeTest.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,70 @@ | ||
package com.kickstarter.services.apiresponses | ||
|
||
import junit.framework.TestCase | ||
import org.junit.Test | ||
|
||
class InternalBuildEnvelopeTest : TestCase() { | ||
|
||
@Test | ||
fun testInternalBuildEnvelopeDefaultInit() { | ||
val internalBuildEnvelope = InternalBuildEnvelope.builder().build(343).changelog("changelog").newerBuildAvailable(true).build() | ||
|
||
assertEquals(internalBuildEnvelope.build(), 343) | ||
assertEquals(internalBuildEnvelope.changelog(), "changelog") | ||
assertEquals(internalBuildEnvelope.newerBuildAvailable(), true) | ||
} | ||
|
||
@Test | ||
fun testInternalBuildEnvelopeEquals_whenFieldsDontMatch_returnsFalse() { | ||
val internalBuildEnvelope1 = InternalBuildEnvelope.builder() | ||
.build(343) | ||
.changelog("changelog1") | ||
.newerBuildAvailable(true) | ||
.build() | ||
|
||
val internalBuildEnvelope2 = internalBuildEnvelope1.toBuilder() | ||
.build(876) | ||
.build() | ||
|
||
val internalBuildEnvelope3 = internalBuildEnvelope1.toBuilder() | ||
.changelog("changelog3") | ||
.build() | ||
|
||
val internalBuildEnvelope4 = internalBuildEnvelope1.toBuilder() | ||
.newerBuildAvailable(false) | ||
.build() | ||
|
||
assertFalse(internalBuildEnvelope1 == internalBuildEnvelope2) | ||
assertFalse(internalBuildEnvelope1 == internalBuildEnvelope3) | ||
assertFalse(internalBuildEnvelope1 == internalBuildEnvelope4) | ||
assertFalse(internalBuildEnvelope2 == internalBuildEnvelope3) | ||
assertFalse(internalBuildEnvelope2 == internalBuildEnvelope4) | ||
assertFalse(internalBuildEnvelope3 == internalBuildEnvelope4) | ||
} | ||
|
||
@Test | ||
fun testInternalBuildEnvelopeEquals_whenFieldsMatch_returnsTrue() { | ||
val internalBuildEnvelope1 = InternalBuildEnvelope.builder() | ||
.build(343) | ||
.changelog("changelog1") | ||
.newerBuildAvailable(true) | ||
.build() | ||
|
||
val internalBuildEnvelope2 = internalBuildEnvelope1 | ||
assertTrue(internalBuildEnvelope1 == internalBuildEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testProjectsEnvelopToBuilder() { | ||
val internalBuildEnvelope = InternalBuildEnvelope.builder() | ||
.build(343) | ||
.changelog("changelog1") | ||
.newerBuildAvailable(true) | ||
.build() | ||
.toBuilder() | ||
.changelog("another_changelog") | ||
.build() | ||
|
||
assertEquals(internalBuildEnvelope.changelog(), "another_changelog") | ||
} | ||
} |