-
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-487: Migrate UpdatesEnvelop.java to kotlin and deprecate Autoparc…
…el (#1606) * Migrate updates envelop to kotlin * tests * Linter * Make constructor private
- Loading branch information
1 parent
20b0634
commit 58fd2fa
Showing
3 changed files
with
259 additions
and
64 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
app/src/main/java/com/kickstarter/services/apiresponses/UpdatesEnvelope.java
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
app/src/main/java/com/kickstarter/services/apiresponses/UpdatesEnvelope.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,114 @@ | ||
package com.kickstarter.services.apiresponses | ||
|
||
import android.os.Parcelable | ||
import com.kickstarter.models.Update | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
class UpdatesEnvelope private constructor( | ||
private val updates: List<Update>, | ||
private val urls: UrlsEnvelope | ||
) : Parcelable { | ||
fun updates() = this.updates | ||
fun urls() = this.urls | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var updates: List<Update> = emptyList(), | ||
private var urls: UrlsEnvelope = UrlsEnvelope.builder().build() | ||
) : Parcelable { | ||
fun updates(updates: List<Update>) = apply { this.updates = updates } | ||
fun urls(urls: UrlsEnvelope) = apply { this.urls = urls } | ||
fun build() = UpdatesEnvelope( | ||
updates = updates, | ||
urls = urls | ||
) | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
updates = updates, | ||
urls = urls | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
var equals = super.equals(other) | ||
if (other is UpdatesEnvelope) { | ||
equals = updates() == other.updates() && | ||
urls() == other.urls() | ||
} | ||
return equals | ||
} | ||
|
||
@Parcelize | ||
class UrlsEnvelope private constructor( | ||
private val api: ApiEnvelope | ||
) : Parcelable { | ||
fun api() = this.api | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var api: ApiEnvelope = ApiEnvelope.builder().build() | ||
) : Parcelable { | ||
fun api(api: ApiEnvelope) = apply { this.api = api } | ||
fun build() = UrlsEnvelope( | ||
api = api | ||
) | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
api = api | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
var equals = super.equals(other) | ||
if (other is UrlsEnvelope) { | ||
equals = api() == other.api() | ||
} | ||
return equals | ||
} | ||
|
||
@Parcelize | ||
class ApiEnvelope private constructor( | ||
private val moreUpdates: String | ||
) : Parcelable { | ||
fun moreUpdates() = this.moreUpdates | ||
|
||
@Parcelize | ||
data class Builder( | ||
private var moreUpdates: String = "" | ||
) : Parcelable { | ||
fun moreUpdates(moreUpdates: String?) = apply { this.moreUpdates = moreUpdates ?: "" } | ||
fun build() = ApiEnvelope( | ||
moreUpdates = moreUpdates | ||
) | ||
} | ||
|
||
fun toBuilder() = Builder( | ||
moreUpdates = moreUpdates | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
fun builder() = Builder() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
var equals = super.equals(other) | ||
if (other is ApiEnvelope) { | ||
equals = moreUpdates() == other.moreUpdates() | ||
} | ||
return equals | ||
} | ||
} | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
app/src/test/java/com/kickstarter/services/apiresponses/UpdatesEnvelopeTest.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,145 @@ | ||
package com.kickstarter.services.apiresponses | ||
|
||
import com.kickstarter.mock.factories.UpdateFactory | ||
import junit.framework.TestCase | ||
import org.junit.Test | ||
|
||
class UpdatesEnvelopeTest : TestCase() { | ||
|
||
@Test | ||
fun testUpdatesEnvelopDefaultInit() { | ||
val updates = listOf(UpdateFactory.update(), UpdateFactory.backersOnlyUpdate()) | ||
val urls = UpdatesEnvelope.UrlsEnvelope.builder().build() | ||
val updatesEnvelope = UpdatesEnvelope.builder().updates(updates).urls(urls).build() | ||
|
||
assertEquals(updatesEnvelope.urls(), urls) | ||
assertEquals(updatesEnvelope.updates(), updates) | ||
} | ||
|
||
@Test | ||
fun testUrlsEnvelopeDefaultInit() { | ||
val api = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope | ||
.builder() | ||
.moreUpdates("more_updates") | ||
.build() | ||
val urlsEnvelope = UpdatesEnvelope.UrlsEnvelope.builder() | ||
.api(api) | ||
.build() | ||
|
||
assertEquals(urlsEnvelope.api(), api) | ||
} | ||
|
||
@Test | ||
fun testApiEnvelopeDefaultInit() { | ||
val apiEnvelope = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("more_updates").build() | ||
|
||
assertEquals(apiEnvelope.moreUpdates(), "more_updates") | ||
} | ||
|
||
@Test | ||
fun testUpdatesEnvelopEquals_whenFieldsDontMatch_returnsFalse() { | ||
val updatesEnvelope1 = UpdatesEnvelope.builder() | ||
.updates(listOf(UpdateFactory.update(), UpdateFactory.backersOnlyUpdate())) | ||
.urls(UpdatesEnvelope.UrlsEnvelope.builder().api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build()).build()) | ||
.build() | ||
|
||
val updatesEnvelope2 = updatesEnvelope1.toBuilder() | ||
.updates(listOf(UpdateFactory.update(), UpdateFactory.update(), UpdateFactory.backersOnlyUpdate())) | ||
.build() | ||
|
||
val updatesEnvelope3 = updatesEnvelope1.toBuilder() | ||
.urls(UpdatesEnvelope.UrlsEnvelope.builder().api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("second_update").build()).build()) | ||
.build() | ||
|
||
assertFalse(updatesEnvelope1 == updatesEnvelope2) | ||
assertFalse(updatesEnvelope1 == updatesEnvelope3) | ||
assertFalse(updatesEnvelope2 == updatesEnvelope3) | ||
} | ||
|
||
@Test | ||
fun testUrlsEnvelopeEquals_whenFieldsDontMatch_returnsFalse() { | ||
val urlsEnvelope1 = UpdatesEnvelope.UrlsEnvelope.builder().api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build()).build() | ||
|
||
val urlsEnvelope2 = urlsEnvelope1.toBuilder() | ||
.api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("second_update").build()).build() | ||
|
||
assertFalse(urlsEnvelope1 == urlsEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testApiEnvelopeEquals_whenFieldsDontMatch_returnsFalse() { | ||
val apiEnvelope1 = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build() | ||
|
||
val apiEnvelope2 = apiEnvelope1.toBuilder() | ||
.moreUpdates("second_update").build() | ||
|
||
assertFalse(apiEnvelope1 == apiEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testUpdatesEnvelopEquals_whenFieldsMatch_returnsTrue() { | ||
val updatesEnvelope1 = UpdatesEnvelope.builder() | ||
.updates(listOf(UpdateFactory.update(), UpdateFactory.backersOnlyUpdate())) | ||
.urls(UpdatesEnvelope.UrlsEnvelope.builder().api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build()).build()) | ||
.build() | ||
|
||
val updatesEnvelope2 = updatesEnvelope1 | ||
|
||
assertTrue(updatesEnvelope1 == updatesEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testUrlsEnvelopeEquals_whenFieldsMatch_returnsTrue() { | ||
val urlsEnvelope1 = UpdatesEnvelope.UrlsEnvelope.builder().api(UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build()).build() | ||
|
||
val urlsEnvelope2 = urlsEnvelope1 | ||
|
||
assertTrue(urlsEnvelope1 == urlsEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testApiEnvelopeEquals_whenFieldsMatch_returnsTrue() { | ||
val apiEnvelope1 = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build() | ||
|
||
val apiEnvelope2 = apiEnvelope1 | ||
|
||
assertTrue(apiEnvelope1 == apiEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testUpdatesEnvelopToBuilder() { | ||
val updates1 = listOf(UpdateFactory.update(), UpdateFactory.backersOnlyUpdate()) | ||
val updates2 = listOf(UpdateFactory.update(), UpdateFactory.update(), UpdateFactory.backersOnlyUpdate()) | ||
|
||
val updatesEnvelope = UpdatesEnvelope.builder().updates(updates1).build().toBuilder().updates(updates2).build() | ||
|
||
assertEquals(updatesEnvelope.updates(), updates2) | ||
} | ||
|
||
@Test | ||
fun testUrlsEnvelopeToBuilder() { | ||
val apiEnvelope1 = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("first_update").build() | ||
val apiEnvelope2 = UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder().moreUpdates("second_update").build() | ||
val urlsEnvelope = | ||
UpdatesEnvelope.UrlsEnvelope.builder() | ||
.api(apiEnvelope1) | ||
.build() | ||
.toBuilder() | ||
.api(apiEnvelope2) | ||
.build() | ||
|
||
assertEquals(urlsEnvelope.api(), apiEnvelope2) | ||
} | ||
|
||
@Test | ||
fun testApiEnvelopeToBuilder() { | ||
val apiEnvelope = | ||
UpdatesEnvelope.UrlsEnvelope.ApiEnvelope.builder() | ||
.moreUpdates("first_update") | ||
.build().toBuilder() | ||
.moreUpdates("second_update") | ||
.build() | ||
|
||
assertEquals(apiEnvelope.moreUpdates(), "second_update") | ||
} | ||
} |