Migration implements RealmMigration { @Override public void migrate(@NonNull DynamicRealm realm, long oldVersion, long newVersion) { RealmSchema schema = realm.getSchema(); if (oldVersion == 0) { createInitialSchema(schema); oldVersion++; } if (oldVersion == 1) { changeHB1ACReadingsToDouble(schema); oldVersion++; } if (oldVersion == 2) { addWeightAndA1CUnitsToUser(schema); oldVersion++; } if (oldVersion == 3) { addReminders(schema); oldVersion++; } if (oldVersion == 4) { migrateAllReadingsToDouble(schema); oldVersion++; } }  @Override void migrate(@NonNull DynamicRealm realm, long oldVersion, long newVersion);  }
@Test public void ProperlyMigrateWeightFromVersion4() { when(objectMock.getInt("reading")).thenReturn(8); migration.migrate(realmMock, 4, 5); inOrder.verify(schemaMock).get("WeightReading"); checkObjectIntMigration("reading", 8); }
@Test public void ProperlyMigratePressureFromVersion4() { when(objectMock.getInt("minReading")).thenReturn(8); when(objectMock.getInt("maxReading")).thenReturn(4); migration.migrate(realmMock, 4, 5); inOrder.verify(schemaMock).get("PressureReading"); checkObjectIntMigration("minReading", 8); checkObjectIntMigration("maxReading", 4); }
@Test public void ProperlyMigrateGlucoseFromVersion4() { when(objectMock.getInt("reading")).thenReturn(8); migration.migrate(realmMock, 4, 5); inOrder.verify(schemaMock).get("GlucoseReading"); checkObjectIntMigration("reading", 8); }
@Test public void ProperlyMigrateUserFromVersion4() { when(objectMock.getInt("custom_range_min")).thenReturn(8); when(objectMock.getInt("custom_range_max")).thenReturn(4); migration.migrate(realmMock, 4, 5); inOrder.verify(schemaMock).get("User"); checkObjectIntMigration("custom_range_min", 8); checkObjectIntMigration("custom_range_max", 4); }
@Test public void ProperlyMigrateCholesterolFromVersion4() { when(objectMock.getInt("totalReading")).thenReturn(8); when(objectMock.getInt("LDLReading")).thenReturn(4); when(objectMock.getInt("HDLReading")).thenReturn(9); migration.migrate(realmMock, 4, 5); inOrder.verify(schemaMock).get("CholesterolReading"); checkObjectIntMigration("totalReading", 8); checkObjectIntMigration("LDLReading", 4); checkObjectIntMigration("HDLReading", 9); }