-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #469 from maskarade/fix_436
Fix #436: ManualStepMigration not working
- Loading branch information
Showing
6 changed files
with
189 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
library/src/test/java/com/github/gfx/android/orma/test/Issue463_ForOrmaDatabaseBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2015 FUJI Goro (gfx). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.github.gfx.android.orma.test; | ||
|
||
import com.github.gfx.android.orma.BuildConfig; | ||
import com.github.gfx.android.orma.test.model.OrmaDatabase; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class Issue463_ForOrmaDatabaseBuilder { | ||
|
||
Context getContext() { | ||
return ApplicationProvider.getApplicationContext(); | ||
} | ||
|
||
@Test | ||
public void dbVersionIsUpToDate() { | ||
OrmaDatabase orma = OrmaDatabase | ||
.builder(getContext()) | ||
.name(null) | ||
.build(); | ||
|
||
assertThat(orma.getConnection().getReadableDatabase().getVersion(), is(not(0))); | ||
assertThat(orma.getConnection().getReadableDatabase().getVersion(), is(BuildConfig.VERSION_CODE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...va/com/github/gfx/android/orma/migration/test/Issue436_ManualStepMigrationNotInvoked.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2015 FUJI Goro (gfx). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.github.gfx.android.orma.migration.test; | ||
|
||
import com.github.gfx.android.orma.core.Database; | ||
import com.github.gfx.android.orma.core.DefaultDatabase; | ||
import com.github.gfx.android.orma.migration.ManualStepMigration; | ||
import com.github.gfx.android.orma.migration.test.util.SchemaData; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import android.content.Context; | ||
|
||
import java.util.ArrayList; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class Issue436_ManualStepMigrationNotInvoked { | ||
static { | ||
System.setProperty("robolectric.logging", "stderr"); | ||
} | ||
|
||
Context getContext() { | ||
return ApplicationProvider.getApplicationContext(); | ||
} | ||
|
||
Database createDatabase() { | ||
return new DefaultDatabase.Provider().provideOnMemoryDatabase(getContext()); | ||
} | ||
|
||
@Test | ||
public void invokedWithoutSteps() { | ||
int initialVersion = 5; | ||
int secondVersion = 7; | ||
|
||
Database db = createDatabase(); | ||
new ManualStepMigration(getContext(), initialVersion, true) | ||
.start(db, new ArrayList<SchemaData>()); | ||
assertThat(db.getVersion(), is(initialVersion)); | ||
|
||
|
||
ManualStepMigration m = new ManualStepMigration(getContext(), secondVersion, true); | ||
m.start(db, new ArrayList<SchemaData>()); | ||
assertThat(db.getVersion(), is(secondVersion)); | ||
|
||
db.close(); | ||
} | ||
|
||
@Test | ||
public void invokedWithSteps() { | ||
int initialVersion = 1; | ||
int secondVersion = 3; | ||
|
||
Database db = createDatabase(); | ||
new ManualStepMigration(getContext(), initialVersion, true) | ||
.start(db, new ArrayList<SchemaData>()); | ||
assertThat(db.getVersion(), is(initialVersion)); | ||
|
||
ManualStepMigration m = new ManualStepMigration(getContext(), secondVersion, true); | ||
m.addStep(secondVersion, new ManualStepMigration.ChangeStep() { | ||
@Override | ||
public void change(@NonNull ManualStepMigration.Helper helper) { | ||
// nop | ||
} | ||
}); | ||
m.start(db, new ArrayList<SchemaData>()); | ||
assertThat(db.getVersion(), is(secondVersion)); | ||
|
||
db.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters