-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Watcher with Kotlin support * version = "0.6.4" * targetSdkVersion 29
- Loading branch information
Evgenii S
authored
Jun 18, 2020
1 parent
c1b5328
commit df3b104
Showing
14 changed files
with
70 additions
and
22 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
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
10 changes: 10 additions & 0 deletions
10
library/src/main/java/com/qautomatron/kopi/library/watcher/Instruction.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,10 @@ | ||
package com.qautomatron.kopi.library.watcher | ||
|
||
import android.os.Bundle | ||
|
||
abstract class Instruction { | ||
var dataContainer = Bundle() | ||
|
||
abstract val description: String | ||
abstract fun checkCondition(): Boolean | ||
} |
36 changes: 36 additions & 0 deletions
36
library/src/main/java/com/qautomatron/kopi/library/watcher/Watcher.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,36 @@ | ||
package com.qautomatron.kopi.library.watcher | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
|
||
object Watcher { | ||
|
||
private const val DEFAULT_TIMEOUT_LIMIT = 1000 * 60 | ||
private const val DEFAULT_INTERVAL = 250 | ||
|
||
var timeoutLimit = DEFAULT_TIMEOUT_LIMIT | ||
var watchInterval = DEFAULT_INTERVAL | ||
|
||
@Throws(Exception::class) | ||
fun waitForCondition(instruction: Instruction) { | ||
var status = Status.CONDITION_NOT_MET | ||
var elapsedTime = 0 | ||
do { | ||
if (instruction.checkCondition()) { | ||
status = Status.CONDITION_MET | ||
} else { | ||
elapsedTime += watchInterval | ||
runBlocking { delay(watchInterval.toLong()) } | ||
} | ||
if (elapsedTime >= timeoutLimit) { | ||
status = Status.TIMEOUT | ||
break | ||
} | ||
} while (status != Status.CONDITION_MET) | ||
if (status == Status.TIMEOUT) throw Exception(instruction.description + " - took more than " + timeoutLimit / 1000 + " seconds. Test stopped.") | ||
} | ||
|
||
enum class Status { | ||
CONDITION_NOT_MET, CONDITION_MET, TIMEOUT | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.