Skip to content

Commit

Permalink
Made visibility for @VisibleForTesting explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
xizzhu committed May 22, 2020
1 parent 4c511e4 commit 891219a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ReadingProgressManager(private val bibleReadingRepository: BibleReadingRep
companion object {
private val TAG: String = ReadingProgressManager::class.java.simpleName

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
const val TIME_SPENT_THRESHOLD_IN_MILLIS = 2500L
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FirebaseAnalyticsProvider(context: Context) : AnalyticsProvider {
firebaseAnalytics.logEvent(event, params?.toBundle())
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun Map<String, Any>.toBundle(): Bundle = Bundle().also { bundle ->
forEach { (key, value) ->
when (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CrashlyticsLogger : Logger {
crashlytics.recordException(e)
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun Throwable.isCoroutineCancellationException(): Boolean {
var rootCause = this
while (rootCause.cause?.let { it != rootCause } == true) rootCause = rootCause.cause!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StrongNumberRepository(private val localStrongNumberStorage: LocalStrongNu

fun download(): Flow<Int> = download(Channel(Channel.CONFLATED), Channel(Channel.CONFLATED))

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun download(versesDownloadProgress: Channel<Int>, wordsDownloadProgress: Channel<Int>) = channelFlow {
val start = elapsedRealtime()
Log.i(TAG, "Start downloading Strong number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TranslationRepository(private val localTranslationStorage: LocalTranslatio
companion object {
private val TAG: String = TranslationRepository::class.java.simpleName

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
const val TRANSLATION_LIST_REFRESH_INTERVAL_IN_MILLIS = 7L * 24L * 3600L * 1000L // 7 day
}

Expand All @@ -63,7 +63,7 @@ class TranslationRepository(private val localTranslationStorage: LocalTranslatio
}
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun updateTranslations(updatedTranslations: List<TranslationInfo>) {
val (available, downloaded) = synchronized(translationsLock) {
val available = mutableMapOf<String, TranslationInfo>()
Expand Down Expand Up @@ -109,11 +109,11 @@ class TranslationRepository(private val localTranslationStorage: LocalTranslatio
updateTranslations(translations)
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
suspend fun translationListTooOld(): Boolean =
currentTimeMillis() - localTranslationStorage.readTranslationListRefreshTimestamp() >= TRANSLATION_LIST_REFRESH_INTERVAL_IN_MILLIS

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
suspend fun readTranslationsFromBackend(): List<TranslationInfo> {
Log.i(TAG, "Start fetching translation list")
val fetchedTranslations = remoteTranslationService.fetchTranslations()
Expand Down Expand Up @@ -170,7 +170,7 @@ class TranslationRepository(private val localTranslationStorage: LocalTranslatio
notifyTranslationsUpdated(available, downloaded)
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
suspend fun downloadTranslation(downloadProgressChannel: SendChannel<Int>, translationInfo: TranslationInfo) {
val start = elapsedRealtime()
Log.i(TAG, "Start downloading translation - ${translationInfo.shortName}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun JsonReader.readListJson(): List<RemoteTranslationInfo> {
throw RuntimeException("Missing 'translations' in list.json")
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun JsonReader.readTranslationsArray(): List<RemoteTranslationInfo> {
val remoteTranslations = ArrayList<RemoteTranslationInfo>()
beginArray()
Expand All @@ -52,7 +52,7 @@ fun JsonReader.readTranslationsArray(): List<RemoteTranslationInfo> {
return remoteTranslations
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun JsonReader.readTranslation(): RemoteTranslationInfo? {
var shortName: String? = null
var name: String? = null
Expand Down Expand Up @@ -103,7 +103,7 @@ fun JsonReader.readBooksJson(): Pair<List<String>, List<String>> {
throw RuntimeException("Illegal JSON format in books.json")
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun JsonReader.readStringsArray(): List<String> {
val strings = ArrayList<String>()
beginArray()
Expand Down Expand Up @@ -154,7 +154,7 @@ fun JsonReader.readStrongNumberVerses(): Map<Int, List<Int>> {
return verses
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun JsonReader.readIntsArray(): List<Int> {
val ints = ArrayList<Int>()
beginArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class TranslationInfoComparator(@SortOrder private val sortOrder: Int) : Compara
return r
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun userLanguage(): String = Locale.getDefault().displayLanguage
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun Activity.share(title: String, text: String) {
?: throw RuntimeException("Failed to create chooser for sharing")
}

@VisibleForTesting
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun PackageManager.chooserForSharing(packageToExclude: String, title: String, text: String): Intent? {
val sendIntent = Intent(Intent.ACTION_SEND).setType("text/plain")
val resolveInfoList = queryIntentActivities(sendIntent, 0)
Expand Down

0 comments on commit 891219a

Please sign in to comment.