-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #19747 from wordpress-mobile/fix/19157-Transaction…
…TooLargeException Replaces bundle usage in the editor with a local database
- Loading branch information
Showing
11 changed files
with
360 additions
and
34 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...s/src/androidTest/java/org/wordpress/android/editor/savedinstance/ParcelableObjectTest.kt
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,42 @@ | ||
package org.wordpress.android.editor.savedinstance | ||
|
||
import android.os.Parcelable | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Assert.assertArrayEquals | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
@HiltAndroidTest | ||
class ParcelableObjectTest { | ||
private lateinit var parcelable: Parcelable | ||
|
||
@Before | ||
fun setUp() { | ||
parcelable = TestParcelable("testData") | ||
} | ||
|
||
@Test | ||
fun testConstructorWithParcelable() { | ||
val parcelableObject = ParcelableObject(parcelable) | ||
val parcelData = parcelableObject.toBytes() | ||
val objectFromParcel = ParcelableObject(parcelData) | ||
assertArrayEquals(objectFromParcel.toBytes(), parcelData) | ||
} | ||
|
||
@Test | ||
fun testConstructorWithByteArray() { | ||
val parcelableObject = ParcelableObject(parcelable) | ||
val data = parcelableObject.toBytes() | ||
val parcelableResult = ParcelableObject(data) | ||
assertArrayEquals(parcelableObject.toBytes(), parcelableResult.toBytes()) | ||
} | ||
|
||
@Test | ||
fun getParcelReturnsTheSameParcelObject() { | ||
val parcelableObject = ParcelableObject(parcelable) | ||
val initialParcel = parcelableObject.getParcel() | ||
val nextParcel = parcelableObject.getParcel() | ||
assertEquals(initialParcel, nextParcel) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../androidTest/java/org/wordpress/android/editor/savedinstance/SavedInstanceDatabaseTest.kt
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,67 @@ | ||
package org.wordpress.android.editor.savedinstance | ||
|
||
import android.content.Context | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import kotlinx.parcelize.parcelableCreator | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidTest | ||
class SavedInstanceDatabaseTest { | ||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@Inject | ||
lateinit var context: Context | ||
|
||
private lateinit var db: SavedInstanceDatabase | ||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
db = SavedInstanceDatabase.getDatabase(context)!! | ||
db.reset(db.writableDatabase) | ||
} | ||
|
||
@Test | ||
fun testStoreAndRetrieve() { | ||
val parcelId = "testParcelId" | ||
val parcelData = TestParcelable("testData") | ||
db.addParcel(parcelId, parcelData) | ||
val result = db.getParcel(parcelId, parcelableCreator<TestParcelable>()) | ||
assertEquals(parcelData, result) | ||
} | ||
|
||
@Test | ||
fun testHasParcel() { | ||
val parcelId = "testParcelId" | ||
val parcelData = TestParcelable("testData") | ||
db.addParcel(parcelId, parcelData) | ||
val result = db.hasParcel(parcelId) | ||
assertTrue(result) | ||
} | ||
|
||
@Test | ||
fun testHasNoParcel() { | ||
val parcelId1 = "testParcelId1" | ||
val parcelId2 = "testParcelId2" | ||
val parcelData = TestParcelable("testData") | ||
db.addParcel(parcelId1, parcelData) | ||
val result = db.hasParcel(parcelId2) | ||
assertFalse(result) | ||
} | ||
|
||
@Test | ||
fun testNullParcel() { | ||
val parcelId = "testParcelId" | ||
db.addParcel(parcelId, null) | ||
val result = db.hasParcel(parcelId) | ||
assertFalse(result) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
WordPress/src/androidTest/java/org/wordpress/android/editor/savedinstance/TestParcelable.kt
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,7 @@ | ||
package org.wordpress.android.editor.savedinstance | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class TestParcelable(val data: String) : Parcelable |
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
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
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
Oops, something went wrong.