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.getRealm();
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(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 RealmTests method copyFromRealm_dynamicRealmObjectThrows.
@Test
public void copyFromRealm_dynamicRealmObjectThrows() {
realm.beginTransaction();
AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
DynamicRealmObject dObj = new DynamicRealmObject(obj);
try {
realm.copyFromRealm(dObj);
fail();
} catch (IllegalArgumentException ignored) {
}
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmTests method copyFromRealm_invalidDepthThrows.
@Test
public void copyFromRealm_invalidDepthThrows() {
realm.beginTransaction();
AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
thrown.expect(IllegalArgumentException.class);
realm.copyFromRealm(obj, -1);
}
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());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmQueryTests method populateTestRealm.
private void populateTestRealm(Realm testRealm, int dataSize) {
testRealm.beginTransaction();
testRealm.deleteAll();
for (int i = 0; i < dataSize; ++i) {
AllTypes allTypes = testRealm.createObject(AllTypes.class);
allTypes.setColumnBoolean((i % 3) == 0);
allTypes.setColumnBinary(new byte[] { 1, 2, 3 });
allTypes.setColumnDate(new Date(DECADE_MILLIS * (i - (dataSize / 2))));
allTypes.setColumnDouble(Math.PI);
allTypes.setColumnFloat(1.2345f + i);
allTypes.setColumnString("test data " + i);
allTypes.setColumnLong(i);
allTypes.setColumnObjectId(new ObjectId(TestHelper.generateObjectIdHexString(i)));
allTypes.setColumnDecimal128(new Decimal128(new BigDecimal(i + ".23456789")));
allTypes.setColumnUUID(UUID.fromString(TestHelper.generateUUIDString(i)));
allTypes.setColumnRealmAny(RealmAny.valueOf(i));
NonLatinFieldNames nonLatinFieldNames = testRealm.createObject(NonLatinFieldNames.class);
nonLatinFieldNames.set델타(i);
nonLatinFieldNames.setΔέλτα(i);
nonLatinFieldNames.set베타(1.2345f + i);
nonLatinFieldNames.setΒήτα(1.2345f + i);
Dog dog = testRealm.createObject(Dog.class);
dog.setAge(i);
dog.setName("test data " + i);
allTypes.setColumnRealmObject(dog);
}
testRealm.commitTransaction();
}
Aggregations