Source:
<code>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) <START> .addPersistedLinkProperty("child", RealmFieldType.OBJECT, "BacklinksTarget", !Property.REQUIRED) <END> .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" )); } }</code><technical_language>@beeender removing original method in next part. <LINK_0> addPersistedLinkProperty(String, RealmFieldType, String) addPersistedLinkProperty(String, RealmFieldType, String, boolean) is confusing, it</technical_language>

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" )); } }