-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring FormulaAndroid slightly and increasing code-coverage. (#335)
- Loading branch information
Showing
7 changed files
with
77 additions
and
49 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
formula-android-tests/src/test/java/com/instacart/formula/FormulaAndroidTest.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,37 @@ | ||
package com.instacart.formula | ||
|
||
import android.app.Application | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class FormulaAndroidTest { | ||
|
||
@Test fun `crashes if initialized twice`() { | ||
|
||
try { | ||
val result = runCatching { | ||
val context = ApplicationProvider.getApplicationContext<Application>() | ||
FormulaAndroid.init(context) {} | ||
FormulaAndroid.init(context) {} | ||
} | ||
val error = result.exceptionOrNull()?.message | ||
Truth.assertThat(error).isEqualTo("can only initialize the store once.") | ||
} finally { | ||
FormulaAndroid.reset() | ||
} | ||
} | ||
|
||
@Test fun `crashes if accessed before initialization`() { | ||
val result = runCatching { | ||
FormulaAndroid.onBackPressed(ActivityUpdateTest.TestActivity()) | ||
} | ||
val errorMessage = result.exceptionOrNull()?.message | ||
Truth.assertThat(errorMessage).isEqualTo( | ||
"Need to call FormulaAndroid.init() from your Application." | ||
) | ||
} | ||
} |
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
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