Skip to content

Instantly share code, notes, and snippets.

@mtrojahn
Created September 14, 2019 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtrojahn/0983dac221aee6f9bd626f8a6644112f to your computer and use it in GitHub Desktop.
Save mtrojahn/0983dac221aee6f9bd626f8a6644112f to your computer and use it in GitHub Desktop.
package com.marcelustrojahn.models
import io.ebean.Ebean
import io.kotlintest.matchers.shouldBe
import io.kotlintest.matchers.shouldNotBe
import io.kotlintest.specs.FreeSpec
class BaseEntityTests: FreeSpec() {
init {
// remember the database will always be empty in the beggining of tests
// so the id will be 1
"should be able to save a Person" {
val person = Person().apply { name = "John" }
Ebean.save(person)
person.id shouldNotBe null // id is filled on save
}
"should be able to select the Person from the database" {
val person = Person.byId(1)
person shouldNotBe null
}
"should be able to update the Person" {
val person = Person.byId(1)
person?.name = "Jack"
Ebean.save(person)
Ebean.find(Person::class.java).where().idEq(1).findOne()?.name shouldBe "Jack"
}
"should be able to delete the Person" {
Person.deleteById(1)
Person.byId(1) shouldBe null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment