-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apollo: Release source code for 51.7
- Loading branch information
Showing
6 changed files
with
101 additions
and
5 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
6 changes: 5 additions & 1 deletion
6
android/apollo/src/main/java/io/muun/apollo/domain/BackgroundTimesService.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
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
82 changes: 82 additions & 0 deletions
82
android/apolloui/src/androidTest/java/io/muun/apollo/domain/BackgroundTimesServiceTest.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,82 @@ | ||
package io.muun.apollo.domain | ||
|
||
import android.content.Context | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.runner.AndroidJUnit4 | ||
import io.muun.apollo.data.preferences.BackgroundTimesRepository | ||
import io.muun.apollo.data.preferences.RepositoryRegistry | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see [Testing documentation](http://d.android.com/tools/testing) | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class BackgroundTimesServiceTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var backgroundTimesService: BackgroundTimesService | ||
private lateinit var backgroundTimesRepository: BackgroundTimesRepository | ||
|
||
@Before | ||
fun setUp() { | ||
context = InstrumentationRegistry.getInstrumentation().targetContext | ||
backgroundTimesRepository = BackgroundTimesRepository(context, RepositoryRegistry()) | ||
backgroundTimesService = BackgroundTimesService( | ||
backgroundTimesRepository | ||
) | ||
|
||
backgroundTimesRepository.clear() | ||
} | ||
|
||
@After | ||
fun cleanUp() { | ||
backgroundTimesRepository.clear() | ||
} | ||
|
||
@Test | ||
fun saveSingleBackgroundEventWorks() { | ||
backgroundTimesService.enterBackground() | ||
backgroundTimesService.enterForeground() | ||
|
||
val bkgTimes = backgroundTimesRepository.getBackgroundTimes() | ||
assertThat(bkgTimes).isNotEmpty | ||
assertThat(bkgTimes.size).isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun recordForegroundBeforeGoingToBackgroundDoesntStoreAnything() { | ||
// E.g on first open we record enterForeground but since we didn't record enterBackground | ||
// we can't calculation bkgEvent duration so we ignore it. | ||
|
||
backgroundTimesService.enterForeground() | ||
|
||
val bkgTimes = backgroundTimesRepository.getBackgroundTimes() | ||
assertThat(bkgTimes).isEmpty() | ||
assertThat(bkgTimes.size).isEqualTo(0) | ||
|
||
saveSingleBackgroundEventWorks() | ||
} | ||
|
||
@Test | ||
fun pruneEventListUponReachingCapLimit() { | ||
|
||
val capLimit = BackgroundTimesService.MAX_BKG_TIMES_ARRAY_SIZE | ||
|
||
for (i in 1..capLimit + 20) { | ||
backgroundTimesService.enterBackground() | ||
backgroundTimesService.enterForeground() | ||
} | ||
|
||
val bkgTimes = backgroundTimesRepository.getBackgroundTimes() | ||
assertThat(bkgTimes).isNotEmpty | ||
// Due to an impl detail we're actually always keeping capLimit + 1 items (hehe) | ||
assertThat(bkgTimes.size).isEqualTo(capLimit + 1) | ||
} | ||
|
||
} |
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