-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 2023-new-options-1
- Loading branch information
Showing
13 changed files
with
447 additions
and
24 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
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
72 changes: 72 additions & 0 deletions
72
corellium/adapter/src/test/kotlin/flank/corellium/adapter/ExecuteAndroidTestPlanKtTest.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,72 @@ | ||
package flank.corellium.adapter | ||
|
||
import flank.corellium.api.AndroidTestPlan | ||
import flank.corellium.client.console.Console | ||
import flank.corellium.client.console.close | ||
import flank.corellium.client.console.flowLogs | ||
import flank.corellium.client.console.sendCommand | ||
import flank.corellium.client.core.Corellium | ||
import flank.corellium.client.core.connectConsole | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.channelFlow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ExecuteAndroidTestPlanKtTest { | ||
|
||
/** | ||
* Connection to [Console] should be closed once subscription detach. | ||
*/ | ||
@Test | ||
fun closeConsole() { | ||
// given | ||
mockkStatic( | ||
"flank.corellium.client.console.ApiKt", | ||
"flank.corellium.client.core.ApiKt", | ||
) | ||
|
||
val instanceId = "1" | ||
val command = "command" | ||
val emitted = mutableListOf<Char>() | ||
val range = ('a'..'z') | ||
val linesFlow: Flow<String> = channelFlow { range.forEach { send("$it"); emitted += it; delay(10) } } | ||
val config = AndroidTestPlan.Config(mapOf(instanceId to listOf(command))) | ||
|
||
val console: Console = mockk(relaxed = true) { | ||
val context = Job() | ||
every { flowLogs() } returns linesFlow | ||
every { coroutineContext } returns context | ||
} | ||
|
||
val corellium: Corellium = mockk(relaxed = true) { | ||
coEvery { connectConsole(instanceId) } returns console | ||
} | ||
|
||
val flow: Flow<String> = executeAndroidTestPlan { corellium } | ||
.invoke(config).first().second | ||
|
||
// when | ||
runBlocking { flow.first { it == "c" } } // Detach the subscription after "c" element | ||
|
||
// then | ||
coVerify(exactly = 1) { console.sendCommand(command) } // Verify sendCommand called. | ||
coVerify(exactly = 1) { console.close() } // Verify console close. | ||
Assert.assertNotEquals(range.last, emitted.last()) // Check the emission not reach last element. | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
unmockkAll() | ||
} | ||
} |
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.