-
Notifications
You must be signed in to change notification settings - Fork 1
/
RealmTestCase.scala
43 lines (34 loc) · 1.11 KB
/
RealmTestCase.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import android.support.test.runner.AndroidJUnit4
import com.github.aafa.model.User
import io.realm.RealmResults
import org.junit.Test
import org.junit.runner.RunWith
/**
* Created by Alexey Afanasev on 25.02.16.
*/
@RunWith(classOf[AndroidJUnit4])
class RealmTestCase extends AbstractRealmTestCase{
@Test
def createUser() = {
addUser(10, "demo")
val firstUser: User = realm.where(classOf[User]).equalTo("id", new Integer(10)).findFirst()
assert(firstUser.name == "demo")
val tenthUser: User = realm.where(classOf[User]).equalTo("name", "demo").findFirst()
assert(tenthUser.id == 10)
}
def addUser(id: Long = 1, name: String = "demo"): Unit = {
val user: User = new User
user.id = id
user.name = name
realmTransaction(_.copyToRealm(user))
}
@Test
def deleteUser() = {
addUser(2, "demo")
val toDelete = realm.where(classOf[User]).equalTo("id", new Integer(2)).findAll()
assert(toDelete.size() == 1)
realmTransaction(_ => {toDelete.removeLast()})
val emptyList: RealmResults[User] = realm.where(classOf[User]).findAll()
assert(emptyList.isEmpty)
}
}