Source:
public void migration_backlinkedSourceFieldDoesntExist() throws ClassNotFoundException { final String realmName = "backlinks-missingSourceField.realm"; RealmConfiguration realmConfig = configFactory.createConfigurationBuilder() .name(realmName) .schema(BacklinksTarget.class, BacklinksSource.class) .build(); OsObjectSchemaInfo targetSchemaInfo = new OsObjectSchemaInfo.Builder("BacklinksTarget") .addPersistedProperty("id", RealmFieldType.INTEGER, !Property.PRIMARY_KEY, !Property.INDEXED, Property.REQUIRED) .addComputedLinkProperty("parents", "BacklinksSource", "childNotExist" ) .build(); OsObjectSchemaInfo sourceSchemaInfo = new OsObjectSchemaInfo.Builder("BacklinksSource") .addPersistedProperty("name", RealmFieldType.STRING, !Property.PRIMARY_KEY, !Property.INDEXED, !Property.REQUIRED) .addPersistedLinkProperty("child", RealmFieldType.OBJECT, "BacklinksTarget", !Property.REQUIRED) .build(); Map<Class<? extends RealmModel>, OsObjectSchemaInfo> infoMap = new HashMap<Class<? extends RealmModel>, OsObjectSchemaInfo>(); infoMap.put(BacklinksTarget.class, targetSchemaInfo); infoMap.put(BacklinksSource.class, sourceSchemaInfo); RealmProxyMediator mediator = spy(realmConfig.getSchemaMediator()); when(mediator.getExpectedObjectSchemaInfoMap()).thenReturn(infoMap); RealmConfiguration spyConfig = spy(realmConfig); when(spyConfig.getSchemaMediator()).thenReturn(mediator); try { Realm localRealm = Realm.getInstance(spyConfig); localRealm.close(); fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), CoreMatchers.containsString( "Property 'BacklinksSource.childNotExist' declared as origin of linking objects property 'BacklinksTarget.parents' does not exist" )); } }

Target:
public void migration_backlinkedSourceFieldDoesntExist() throws ClassNotFoundException { final String realmName = "backlinks-missingSourceField.realm"; RealmConfiguration realmConfig = configFactory.createConfigurationBuilder() .name(realmName) .schema(BacklinksTarget.class, BacklinksSource.class) .build(); OsObjectSchemaInfo targetSchemaInfo = new OsObjectSchemaInfo.Builder("BacklinksTarget") .addPersistedProperty("id", RealmFieldType.INTEGER, !Property.PRIMARY_KEY, !Property.INDEXED, Property.REQUIRED) .addComputedLinkProperty("parents", "BacklinksSource", "childNotExist" ) .build(); OsObjectSchemaInfo sourceSchemaInfo = new OsObjectSchemaInfo.Builder("BacklinksSource") .addPersistedProperty("name", RealmFieldType.STRING, !Property.PRIMARY_KEY, !Property.INDEXED, !Property.REQUIRED) .addPersistedLinkProperty("child", RealmFieldType.OBJECT, "BacklinksTarget") .build(); Map<Class<? extends RealmModel>, OsObjectSchemaInfo> infoMap = new HashMap<Class<? extends RealmModel>, OsObjectSchemaInfo>(); infoMap.put(BacklinksTarget.class, targetSchemaInfo); infoMap.put(BacklinksSource.class, sourceSchemaInfo); RealmProxyMediator mediator = spy(realmConfig.getSchemaMediator()); when(mediator.getExpectedObjectSchemaInfoMap()).thenReturn(infoMap); RealmConfiguration spyConfig = spy(realmConfig); when(spyConfig.getSchemaMediator()).thenReturn(mediator); try { Realm localRealm = Realm.getInstance(spyConfig); localRealm.close(); fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), CoreMatchers.containsString( "Property 'BacklinksSource.childNotExist' declared as origin of linking objects property 'BacklinksTarget.parents' does not exist" )); } }