-
Notifications
You must be signed in to change notification settings - Fork 1
/
RelationshipsTestCase.scala
42 lines (33 loc) · 1.18 KB
/
RelationshipsTestCase.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
import android.support.test.runner.AndroidJUnit4
import com.github.aafa.model.{Role, Email, User}
import io.realm.{RealmQuery, RealmResults}
import org.junit.Test
import org.junit.runner.RunWith
/**
* Created by Alexey Afanasev on 25.02.16.
*/
@RunWith(classOf[AndroidJUnit4])
class RelationshipsTestCase extends AbstractRealmTestCase{
def addUser(id: Long = 1, name: String = "su"): Unit = {
realmTransaction(realm => {
val user: User = realm.createObject(classOf[User])
user.id = id
user.name = name
val email: Email = realm.createObject(classOf[Email])
email.value = "[email protected]"
user.email = email
val role: Role = realm.createObject(classOf[Role])
role.name = "admin"
user.role = role
})
}
@Test
def createUserWithRelations() = {
addUser()
val realmQuery: RealmQuery[User] = realm.where(classOf[User])
assert(realmQuery.equalTo("id", new Integer(1)).findFirst().name == "su")
assert(realmQuery.equalTo("name", "su").findFirst().id == 1)
assert(realmQuery.equalTo("email.value", "[email protected]").findFirst().id == 1)
assert(realmQuery.equalTo("role.name", "admin").findFirst().id == 1)
}
}