use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmResultsTests method removeAllChangeListeners.
@Test
@RunTestInLooperThread
public void removeAllChangeListeners() {
final AtomicInteger listenersTriggered = new AtomicInteger(0);
final Realm realm = looperThread.realm;
RealmResults<AllTypes> collection = realm.where(AllTypes.class).findAll();
RealmChangeListener<RealmResults<AllTypes>> listenerA = new RealmChangeListener<RealmResults<AllTypes>>() {
@Override
public void onChange(RealmResults<AllTypes> object) {
listenersTriggered.incrementAndGet();
}
};
RealmChangeListener<RealmResults<AllTypes>> listenerB = new RealmChangeListener<RealmResults<AllTypes>>() {
@Override
public void onChange(RealmResults<AllTypes> object) {
listenersTriggered.incrementAndGet();
}
};
looperThread.keepStrongReference.add(collection);
collection.addChangeListener(listenerA);
collection.addChangeListener(listenerB);
collection.removeAllChangeListeners();
realm.beginTransaction();
realm.createObject(AllTypes.class);
realm.commitTransaction();
// The above commit should have put a REALM_CHANGED event on the Looper queue before this runnable.
looperThread.postRunnable(new Runnable() {
@Override
public void run() {
if (listenersTriggered.get() == 0) {
looperThread.testComplete();
} else {
fail("Listeners wasn't removed");
}
}
});
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmResultsTests method size_returns_Integer_MAX_VALUE_for_huge_results.
@Test
public void size_returns_Integer_MAX_VALUE_for_huge_results() {
final Collection collection = Mockito.mock(Collection.class);
final RealmResults<AllTypes> targetResult = TestHelper.newRealmResults(realm, collection, AllTypes.class);
Mockito.when(collection.isLoaded()).thenReturn(true);
Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE) - 1);
assertEquals(Integer.MAX_VALUE - 1, targetResult.size());
Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE));
assertEquals(Integer.MAX_VALUE, targetResult.size());
Mockito.when(collection.size()).thenReturn(((long) Integer.MAX_VALUE) + 1);
assertEquals(Integer.MAX_VALUE, targetResult.size());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmResultsTests method addChangeListener_twice.
@Test
@RunTestInLooperThread
public void addChangeListener_twice() {
final AtomicInteger listenersTriggered = new AtomicInteger(0);
final Realm realm = looperThread.realm;
RealmResults<AllTypes> collection = realm.where(AllTypes.class).findAll();
RealmChangeListener<RealmResults<AllTypes>> listener = new RealmChangeListener<RealmResults<AllTypes>>() {
@Override
public void onChange(RealmResults<AllTypes> object) {
listenersTriggered.incrementAndGet();
}
};
realm.addChangeListener(new RealmChangeListener<Realm>() {
@Override
public void onChange(Realm object) {
listenersTriggered.incrementAndGet();
looperThread.postRunnable(new Runnable() {
@Override
public void run() {
if (listenersTriggered.get() == 1) {
looperThread.testComplete();
} else {
fail("Only global listener should be triggered");
}
}
});
}
});
// Adding it twice will be ignored, so removing it will not cause the listener to be triggered.
looperThread.keepStrongReference.add(collection);
collection.addChangeListener(listener);
collection.addChangeListener(listener);
collection.removeChangeListener(listener);
realm.beginTransaction();
realm.createObject(AllTypes.class);
realm.commitTransaction();
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmQueryTests method greaterThanOrEqualTo_date.
@Test
public void greaterThanOrEqualTo_date() {
final int TEST_OBJECTS_COUNT = 200;
populateTestRealm(realm, TEST_OBJECTS_COUNT);
RealmResults<AllTypes> resultList;
resultList = realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_DATE, new Date(Long.MIN_VALUE)).findAll();
assertEquals(TEST_OBJECTS_COUNT, resultList.size());
resultList = realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * -80)).findAll();
assertEquals(180, resultList.size());
resultList = realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_DATE, new Date(0)).findAll();
assertEquals(TEST_OBJECTS_COUNT / 2, resultList.size());
resultList = realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * 80)).findAll();
assertEquals(20, resultList.size());
resultList = realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_DATE, new Date(Long.MAX_VALUE)).findAll();
assertEquals(0, resultList.size());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmQueryTests method greaterThan_date.
@Test
public void greaterThan_date() {
final int TEST_OBJECTS_COUNT = 200;
populateTestRealm(realm, TEST_OBJECTS_COUNT);
RealmResults<AllTypes> resultList;
resultList = realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_DATE, new Date(Long.MIN_VALUE)).findAll();
assertEquals(TEST_OBJECTS_COUNT, resultList.size());
resultList = realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * -80)).findAll();
assertEquals(179, resultList.size());
resultList = realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_DATE, new Date(0)).findAll();
assertEquals(TEST_OBJECTS_COUNT / 2 - 1, resultList.size());
resultList = realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * 80)).findAll();
assertEquals(19, resultList.size());
resultList = realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_DATE, new Date(Long.MAX_VALUE)).findAll();
assertEquals(0, resultList.size());
}
Aggregations