Skip to content

Instantly share code, notes, and snippets.

@kinnerapriyap
kinnerapriyap / Person.kt
Last active November 14, 2018 03:24
data class in Kotlin
data class Person(
val id: Long,
val name: String,
val addressLine1: String,
val addressLine2: String,
val city: String,
val country: String,
val pincode: Int,
val phoneNumber: String
)
@kinnerapriyap
kinnerapriyap / Person.kt
Created November 14, 2018 10:17
@entity data class in kotlin
@Entity
data class Person(
@PrimaryKey(autoGenerate = true)
val id: Long,
@SerializedName("name")
val personName: String,
val addressLine1: String,
val addressLine2: String,
val city: String,
val country: String,
@kinnerapriyap
kinnerapriyap / Address.kt
Created November 14, 2018 10:23
@entity data class in Kotlin with @Embedded
data class Address(
val addressLine1: String,
val addressLine2: String,
val city: String,
val country: String,
val pincode: Int
)
@kinnerapriyap
kinnerapriyap / Item.kt
Created November 15, 2018 09:37
@entity with composite primary key
@Entity(primaryKeys = {"categoryId","itemID"})
data class Item {
...
}
@Entity
data class Item {
@PrimaryKey
@Embedded ItemId id,
...
}
data class ItemId {
long categoryId,
int itemId
@kinnerapriyap
kinnerapriyap / Item.java
Last active November 16, 2018 06:36
@entity, @EmbeddedId and @embeddable in Java
@Entity
public class Item {
@EmbeddedId ItemId id;
...
}
@Embeddable
class ItemId {
long categoryId;
int itemId;
lateinit var person: Person
beforeEachGroup {
person = Person(
name = "name",
address = "address",
age = 60,
isActive = false
)
}
object PersonSpec : Spek({
})
describe("isPersonRetired") {
describe("when isActive is true") {
beforeEachGroup {
person = person.copy(isActive = true)
}
describe("when getAge is greater than RETIREMENT_AGE") {
beforeEachGroup { person = person.copy(age = 65) }
}
describe("when getAge is less than RETIREMENT_AGE") {
beforeEachGroup { person = person.copy(age = 55) }
describe("when isActive is false") {
beforeEachGroup {
person = person.copy(isActive = false)
}
...
describe("when getAge is less than RETIREMENT_AGE") {
beforeEachGroup {
person = person.copy(age = 55)
}
it("should return false") {