Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTV-445 : Migrate ProjectNotificationBody.java to kotlin and deprecate Autoparcel #1581

Merged
merged 2 commits into from Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

@@ -0,0 +1,47 @@
package com.kickstarter.services.apirequests

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
class ProjectNotificationBody private constructor(
private val email: Boolean,
private val mobile: Boolean
) :
Parcelable {
fun email() = this.email
fun mobile() = this.mobile

@Parcelize
data class Builder(
private var email: Boolean = false,
private var mobile: Boolean = false,
) : Parcelable {
fun email(email: Boolean) = apply { this.email = email }
fun mobile(mobile: Boolean) = apply { this.mobile = mobile }

fun build() = ProjectNotificationBody(
email = email,
mobile = mobile
)
}

fun toBuilder() = Builder(
email = email,
mobile = mobile
)

companion object {
@JvmStatic
fun builder() = Builder()
}

override fun equals(obj: Any?): Boolean {
var equals = super.equals(obj)
if (obj is ProjectNotificationBody) {
equals = email() == obj.email() &&
mobile() == obj.mobile()
}
return equals
}
}
@@ -0,0 +1,54 @@
package com.kickstarter.models

import com.kickstarter.KSRobolectricTestCase
import com.kickstarter.services.apirequests.ProjectNotificationBody
import org.junit.Test

class ProjectNotificationBodyTest : KSRobolectricTestCase() {

@Test
fun testDefaultInit() {
val projectNotificationBody = ProjectNotificationBody.builder()
.email(true)
.mobile(true)
.build()

assertTrue(projectNotificationBody.email())
assertTrue(projectNotificationBody.mobile())
}

@Test
fun testDefaultToBuilder() {
val projectNotificationBody = ProjectNotificationBody.builder().build().toBuilder().email(true).build()
assertTrue(projectNotificationBody.email())
}

@Test
fun testProjectNotificationBody_equalFalse() {
val projectNotificationBody = ProjectNotificationBody.builder().build()
val projectNotificationBody2 = ProjectNotificationBody.builder()
.email(true).build()
val projectNotificationBody3 = ProjectNotificationBody.builder()
.mobile(true)
.build()
val projectNotificationBody4 = ProjectNotificationBody.builder()
.email(true)
.mobile(true)
.build()

assertFalse(projectNotificationBody == projectNotificationBody2)
assertFalse(projectNotificationBody == projectNotificationBody3)
assertFalse(projectNotificationBody == projectNotificationBody4)

assertFalse(projectNotificationBody3 == projectNotificationBody2)
assertFalse(projectNotificationBody3 == projectNotificationBody4)
}

@Test
fun testProjectNotificationBody_equalTrue() {
val projectNotificationBody1 = ProjectNotificationBody.builder().build()
val projectNotificationBody2 = ProjectNotificationBody.builder().build()

assertEquals(projectNotificationBody1, projectNotificationBody2)
}
}