use of io.realm.entities.DictionaryAllTypes in project realm-java by realm.
the class RealmResultsTests method canHoldPrimitiveTypes.
/**
* Test we can also hold primitive values in RealmResults. This is a somewhat concealed feature
* since we do not allow queries on primitive types as per version 10.3.1. The only place in
* the SDK that returns primitive RealmResults is the {@link RealmDictionary#values()}.
*/
@Test
public void canHoldPrimitiveTypes() {
String KEY_1 = "KEY_1";
String KEY_2 = "KEY_2";
String VALUE_1 = "VALUE_1";
String VALUE_2 = "VALUE_2";
RealmDictionary<String> stringDictionary = new RealmDictionary<>();
stringDictionary.put(KEY_1, VALUE_1);
stringDictionary.put(KEY_2, VALUE_2);
realm.beginTransaction();
DictionaryAllTypes object = new DictionaryAllTypes();
object.setColumnStringDictionary(stringDictionary);
DictionaryAllTypes objectFromRealm = realm.copyToRealm(object);
realm.commitTransaction();
RealmDictionary<String> stringDictionaryFromRealm = objectFromRealm.getColumnStringDictionary();
assertNotNull(stringDictionaryFromRealm);
Collection<String> values = stringDictionaryFromRealm.values();
assertNotNull(values);
assertTrue(values instanceof RealmResults);
assertTrue(values.contains(VALUE_1));
assertTrue(values.contains(VALUE_2));
// Not returning RealmResults per se, but rather wrapped in a HashSet
Set<String> keySet = stringDictionaryFromRealm.keySet();
assertNotNull(keySet);
assertTrue(keySet.contains(KEY_1));
assertTrue(keySet.contains(KEY_2));
}
use of io.realm.entities.DictionaryAllTypes in project realm-java by realm.
the class RealmQueryTests method catchInsertSupportsDictionaries.
// The purpose of this test case is to catch when insert supports objects containing dictionaries,
// to then we can use AllJavaTypes instead of AllJavaTypesUnsupportedTypes.
// See: https://github.com/realm/realm-java/issues/7435
@Test(expected = IllegalStateException.class)
public void catchInsertSupportsDictionaries() {
DictionaryAllTypes dictionaryAllTypes = new DictionaryAllTypes();
realm.insert(dictionaryAllTypes);
}
use of io.realm.entities.DictionaryAllTypes in project realm-java by realm.
the class RealmQueryTests method catchInsertOrUpdateSupportsDictionaries.
// The purpose of this test case is to catch when insert supports objects containing dictionaries,
// to then we can use AllJavaTypes instead of AllJavaTypesUnsupportedTypes.
// See: https://github.com/realm/realm-java/issues/7435
@Test(expected = IllegalStateException.class)
public void catchInsertOrUpdateSupportsDictionaries() {
DictionaryAllTypes dictionaryAllTypes = new DictionaryAllTypes();
realm.insertOrUpdate(dictionaryAllTypes);
}
use of io.realm.entities.DictionaryAllTypes in project realm-java by realm.
the class RealmQueryTests method fillDictionaryTests.
private void fillDictionaryTests() {
realm.executeTransaction(transactionRealm -> {
DictionaryAllTypes allTypes1 = realm.createObject(DictionaryAllTypes.class);
allTypes1.getColumnStringDictionary().put("hello world1", "Test1");
DictionaryAllTypes allTypes2 = realm.createObject(DictionaryAllTypes.class);
allTypes2.getColumnStringDictionary().put("hello world1", "Test2");
DictionaryAllTypes allTypes3 = realm.createObject(DictionaryAllTypes.class);
allTypes3.getColumnStringDictionary().put("hello world2", "Test2");
});
}
use of io.realm.entities.DictionaryAllTypes in project realm-java by realm.
the class RealmQueryTests method dictionary_containsKey.
@Test
public void dictionary_containsKey() {
fillDictionaryTests();
RealmResults<DictionaryAllTypes> results = realm.where(DictionaryAllTypes.class).containsKey(DictionaryAllTypes.FIELD_STRING_DICTIONARY, "hello world1").findAll();
assertEquals(2, results.size());
// We can't assert on values since we don't know the order in which the results are delivered, so better to assert that the keys are contained in the results
DictionaryAllTypes results0 = results.get(0);
assertNotNull(results0);
assertTrue(results0.getColumnStringDictionary().containsKey("hello world1"));
DictionaryAllTypes results1 = results.get(1);
assertNotNull(results1);
assertTrue(results1.getColumnStringDictionary().containsKey("hello world1"));
}
Aggregations