use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class ManagedOrderedRealmCollectionTests method runMethodOnWrongThread.
private boolean runMethodOnWrongThread(final ListMethod method) throws ExecutionException, InterruptedException {
realm.beginTransaction();
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<Boolean> future = executorService.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
// Defines expected exception.
Class<? extends Throwable> expected = IllegalStateException.class;
if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch(method) {
case ADD_INDEX:
case ADD_ALL_INDEX:
case SET:
case REMOVE_INDEX:
expected = UnsupportedOperationException.class;
break;
default:
}
}
try {
switch(method) {
case FIRST:
collection.first();
break;
case LAST:
collection.last();
break;
case ADD_INDEX:
collection.add(0, new AllJavaTypes());
break;
case ADD_ALL_INDEX:
collection.addAll(0, Collections.singletonList(new AllJavaTypes()));
break;
case GET_INDEX:
collection.get(0);
break;
case INDEX_OF:
collection.indexOf(new AllJavaTypes());
break;
case LAST_INDEX_OF:
collection.lastIndexOf(new AllJavaTypes());
break;
case LIST_ITERATOR:
collection.listIterator();
break;
case LIST_ITERATOR_INDEX:
collection.listIterator(0);
break;
case REMOVE_INDEX:
collection.remove(0);
break;
case SET:
collection.set(0, new AllJavaTypes());
break;
case SUBLIST:
collection.subList(0, 1);
break;
}
return false;
} catch (Throwable t) {
if (!t.getClass().equals(expected)) {
return false;
}
}
return true;
}
});
Boolean result = future.get();
realm.cancelTransaction();
return result;
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class ManagedRealmCollectionTests method where_lessThanGreaterThan.
/**
* Tests to see if a particular item that does exist in the same Realm does not
* exist in the result set of another query.
*/
@Test
public void where_lessThanGreaterThan() {
RealmResults<AllJavaTypes> items = realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, 1000).findAll();
AllJavaTypes anotherType = realm.where(AllJavaTypes.class).greaterThan(AllJavaTypes.FIELD_LONG, 1000).findFirst();
assertFalse("Should not be able to find item in another result list.", items.contains(anotherType));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class ManagedRealmCollectionTests method contains_deletedRealmObject.
@Test
public void contains_deletedRealmObject() {
AllJavaTypes obj = collection.iterator().next();
realm.beginTransaction();
obj.deleteFromRealm();
realm.commitTransaction();
assertFalse(collection.contains(obj));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class ManagedRealmCollectionTests method where_contains.
@Test
public void where_contains() {
RealmQuery<AllJavaTypes> query = realm.where(AllJavaTypes.class).findAll().where();
AllJavaTypes item = query.findFirst();
assertTrue("Item should exist in results.", query.findAll().contains(item));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class CollectionTests method populateRealm.
protected void populateRealm(Realm realm, int objects) {
realm.beginTransaction();
realm.delete(AllJavaTypes.class);
realm.delete(NonLatinFieldNames.class);
if (objects > 0) {
for (int i = 0; i < objects; i++) {
AllJavaTypes obj = realm.createObject(AllJavaTypes.class, i);
fillObject(i, objects, obj);
NonLatinFieldNames nonLatinFieldNames = realm.createObject(NonLatinFieldNames.class);
nonLatinFieldNames.set델타(i);
nonLatinFieldNames.setΔέλτα(i);
// Sets the linked object to itself.
obj.setFieldObject(obj);
}
// Adds all items to the RealmList on the first object.
AllJavaTypes firstObj = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_ID, 0).findFirst();
RealmResults<AllJavaTypes> listData = realm.where(AllJavaTypes.class).findAllSorted(AllJavaTypes.FIELD_ID, Sort.ASCENDING);
RealmList<AllJavaTypes> list = firstObj.getFieldList();
for (int i = 0; i < listData.size(); i++) {
list.add(listData.get(i));
}
}
realm.commitTransaction();
}
Aggregations