realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Mocking unmanaged RealmObject observable #3861

Open leesunghyun opened 7 years ago

leesunghyun commented 7 years ago

Goal

I want to make mock object of asObservable() about findFirstAsync. I found a comment in RealmObject.

// TODO Is this true? Should we just return Observable.just(object) ?
 throw new IllegalArgumentException("Cannot create Observables from unmanaged RealmObjects");

Is there any other way to make mock observable?

Expected Results

Create mock observable object.

Actual Results

java.lang.IllegalArgumentException: Cannot create Observables from unmanaged RealmObjects

Code Sample

PowerMockito.`when`(realmQuery.findFirstAsync()).thenReturn(realmObject)
PowerMockito.`when`(realmObject.asObservable<Object()).thenReturn(Observable.just(realmObject))

Version of Realm and tooling

Realm version(s): 2.2

Realm sync feature enabled: no

Android Studio version: 2.2

Which Android version and device: nexus 5x

kneth commented 7 years ago

@leesunghyun No current plan but we accept pull request :-)

I move it to our backlog and mark it as an enhancement.