Search in sources :

Example 11 with RealmProxyMediator

use of io.realm.internal.RealmProxyMediator in project realm-java by realm.

the class RealmProxyMediatorTests method validateTable_noDuplicateIndexInIndexFields.

@Test
public void validateTable_noDuplicateIndexInIndexFields() {
    RealmProxyMediator mediator = realm.getConfiguration().getSchemaMediator();
    CatRealmProxy.CatColumnInfo columnInfo;
    columnInfo = (CatRealmProxy.CatColumnInfo) mediator.validateTable(Cat.class, realm.sharedRealm, false);
    final Set<Long> indexSet = new HashSet<Long>();
    int indexCount = 0;
    indexSet.add(columnInfo.nameIndex);
    indexCount++;
    indexSet.add(columnInfo.ageIndex);
    indexCount++;
    indexSet.add(columnInfo.heightIndex);
    indexCount++;
    indexSet.add(columnInfo.weightIndex);
    indexCount++;
    indexSet.add(columnInfo.hasTailIndex);
    indexCount++;
    indexSet.add(columnInfo.birthdayIndex);
    indexCount++;
    indexSet.add(columnInfo.ownerIndex);
    indexCount++;
    indexSet.add(columnInfo.scaredOfDogIndex);
    indexCount++;
    assertEquals(indexCount, indexSet.size());
}
Also used : RealmProxyMediator(io.realm.internal.RealmProxyMediator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with RealmProxyMediator

use of io.realm.internal.RealmProxyMediator in project realm-java by realm.

the class ColumnInfoTests method clone_hasSameValue.

@Test
public void clone_hasSameValue() {
    final RealmProxyMediator mediator = realm.getConfiguration().getSchemaMediator();
    final CatRealmProxy.CatColumnInfo columnInfo;
    columnInfo = (CatRealmProxy.CatColumnInfo) mediator.validateTable(Cat.class, realm.sharedRealm, false);
    columnInfo.nameIndex = 1;
    columnInfo.ageIndex = 2;
    columnInfo.heightIndex = 3;
    columnInfo.weightIndex = 4;
    columnInfo.hasTailIndex = 5;
    columnInfo.birthdayIndex = 6;
    columnInfo.ownerIndex = 7;
    columnInfo.scaredOfDogIndex = 8;
    CatRealmProxy.CatColumnInfo copy = columnInfo.clone();
    // Modifies original object.
    columnInfo.nameIndex = 0;
    columnInfo.ageIndex = 0;
    columnInfo.heightIndex = 0;
    columnInfo.weightIndex = 0;
    columnInfo.hasTailIndex = 0;
    columnInfo.birthdayIndex = 0;
    columnInfo.ownerIndex = 0;
    columnInfo.scaredOfDogIndex = 0;
    assertNotSame(columnInfo, copy);
    assertEquals(1, copy.nameIndex);
    assertEquals(2, copy.ageIndex);
    assertEquals(3, copy.heightIndex);
    assertEquals(4, copy.weightIndex);
    assertEquals(5, copy.hasTailIndex);
    assertEquals(6, copy.birthdayIndex);
    assertEquals(7, copy.ownerIndex);
    assertEquals(8, copy.scaredOfDogIndex);
    // Current implementation shares the indices map between copies.
    assertSame(columnInfo.getIndicesMap(), copy.getIndicesMap());
}
Also used : RealmProxyMediator(io.realm.internal.RealmProxyMediator) Test(org.junit.Test)

Aggregations

RealmProxyMediator (io.realm.internal.RealmProxyMediator)12 Test (org.junit.Test)4 RealmException (io.realm.exceptions.RealmException)3 RealmMigrationNeededException (io.realm.exceptions.RealmMigrationNeededException)3 ColumnIndices (io.realm.internal.ColumnIndices)3 ColumnInfo (io.realm.internal.ColumnInfo)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 RealmFileException (io.realm.exceptions.RealmFileException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JSONException (org.json.JSONException)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1