Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isConfigured #378

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,13 @@ class Purchases @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) intern
@JvmStatic
var proxyURL: URL? = null

/**
* True if [configure] has been called and [Purchases.sharedInstance] is set
*/
@JvmStatic
val isConfigured: Boolean
get() = this.backingFieldSharedInstance != null

/**
* Configures an instance of the Purchases SDK with a specified API key. The instance will
* be set as a singleton. You should access the singleton instance using [Purchases.sharedInstance]
Expand Down
11 changes: 11 additions & 0 deletions purchases/src/test/java/com/revenuecat/purchases/PurchasesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,17 @@ class PurchasesTest {
assertThat(receivedUserCancelled).isFalse()
}

@Test
fun `isConfigured is true if there's an instance set`() {
assertThat(Purchases.isConfigured).isTrue()
}

@Test
fun `isConfigured is false if there's no instance set`() {
Purchases.backingFieldSharedInstance = null
assertThat(Purchases.isConfigured).isFalse()
}

private fun mockBackend(errorGettingPurchaserInfo: PurchasesError? = null) {
with(mockBackend) {
if (errorGettingPurchaserInfo != null) {
Expand Down