diff --git a/README.md b/README.md index 979305e..7fab796 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Modules: Commander is [available on jcenter](https://jcenter.bintray.com/com/gojuno/commander). ```groovy -compile 'com.gojuno.commander:os:some-version' -compile 'com.gojuno.commander:android:some-version' +compile 'com.gojuno.commander:os:${latestVersion}' +compile 'com.gojuno.commander:android:${latestVersion}' ``` All the releases and changelogs can be found on [Releases Page](https://github.com/gojuno/commander/releases). @@ -43,6 +43,3 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` - -[spoon]: https://github.com/square/spoon -[test sharding]: https://developer.android.com/topic/libraries/testing-support-library/index.html#ajur-sharding diff --git a/android/build.gradle b/android/build.gradle index 121e31c..318d11f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,28 +1,7 @@ -apply plugin: 'kotlin' -apply plugin: 'org.junit.platform.gradle.plugin' -apply from: '../gradle/publishing.gradle' +description = "Functions to work with Android SDK Tools like adb, avdmanager, sdkmanager." dependencies { - compile libraries.os - compile libraries.kotlinStd - compile libraries.kotlinRuntime - compile libraries.kotlinReflect - compile libraries.rxJava + api project(':os') } -dependencies { - testCompile libraries.spek - testCompile libraries.spekSubjectExtension - testCompile libraries.spekJunitPlatformEngine - testCompile libraries.assertJ -} - -junitPlatform { - platformVersion = versions.junitPlatform - - filters { - engines { - include 'spek' - } - } -} +apply from: '../gradle/publishing.gradle' \ No newline at end of file diff --git a/android/gradle.properties b/android/gradle.properties deleted file mode 100644 index 2365cba..0000000 --- a/android/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -name=android -description=Functions to work with Android SDK Tools like adb, avdmanager, sdkmanager. diff --git a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt index 56eaa9c..ea97dc6 100644 --- a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt +++ b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt @@ -1,30 +1,33 @@ +@file:Suppress("unused") + package com.gojuno.commander.android import com.gojuno.commander.os.Notification import com.gojuno.commander.os.log import com.gojuno.commander.os.nanosToHumanReadableTime import com.gojuno.commander.os.process -import rx.Observable -import rx.Single +import io.reactivex.Observable +import io.reactivex.Single import java.io.File import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.MINUTES import java.util.concurrent.TimeUnit.SECONDS +import kotlin.system.exitProcess val androidHome: String by lazy { requireNotNull(System.getenv("ANDROID_HOME")) { "Please specify ANDROID_HOME env variable" } } -val adb: String by lazy { "$androidHome${File.pathSeparator}platform-tools${File.pathSeparator}adb" } +val adb: String by lazy { "$androidHome${File.separator}platform-tools${File.separator}adb" } private val buildTools: String? by lazy { - File(androidHome, "build-tools") + requireNotNull(File(androidHome, "build-tools") .listFiles() - .sortedArray() - .lastOrNull() - ?.absolutePath + ?.sortedArray() + ?.lastOrNull() + ?.absolutePath) { "" } } -val aapt: String by lazy { buildTools?.let { "$buildTools${File.pathSeparator}aapt" } ?: "" } +val aapt: String by lazy { buildTools?.let { "$buildTools${File.separator}aapt" } ?: "" } internal fun Observable.trimmedOutput() = this .ofType(Notification.Exit::class.java) - .toSingle() + .singleOrError() .map { it.output.readText().trim() } fun AdbDevice.externalStorage(): Single = process(listOf(adb, "-s", id, "shell", "printenv", "EXTERNAL_STORAGE")) @@ -35,7 +38,7 @@ fun AdbDevice.deviceModel(): Single = process(listOf(adb, "-s", id, "she .trimmedOutput() .doOnError { log("Could not get model name of device $id, error = $it") } -fun connectedAdbDevices(): Observable> = process(listOf(adb, "devices"), unbufferedOutput = true) +fun connectedAdbDevices(): Single> = process(listOf(adb, "devices"), unbufferedOutput = true) .ofType(Notification.Exit::class.java) .map { it.output.readText() } .map { @@ -52,8 +55,8 @@ fun connectedAdbDevices(): Observable> = process(listOf(adb, "dev shouldRetry } - .flatMapIterable { - it + .flatMapIterable { adbStdOut -> + adbStdOut .substringAfter("List of devices attached") .split(System.lineSeparator()) .map { it.trim() } @@ -81,9 +84,8 @@ fun connectedAdbDevices(): Observable> = process(listOf(adb, "dev fun AdbDevice.log(message: String) = com.gojuno.commander.os.log("[$id] $message") fun AdbDevice.installApk(pathToApk: String, timeout: Pair = 2 to MINUTES): Observable { - val adbDevice = this val installApk = process( - commandAndArgs = listOf(adb, "-s", adbDevice.id, "install", "-r", pathToApk), + commandAndArgs = listOf(adb, "-s", id, "install", "-r", pathToApk), unbufferedOutput = true, timeout = timeout ) @@ -104,23 +106,22 @@ fun AdbDevice.installApk(pathToApk: String, timeout: Pair = 2 to when (success) { true -> { - adbDevice.log("Successfully installed apk in ${duration.nanosToHumanReadableTime()}, pathToApk = $pathToApk") + log("Successfully installed apk in ${duration.nanosToHumanReadableTime()}, pathToApk = $pathToApk") } false -> { - adbDevice.log("Failed to install apk $pathToApk") - System.exit(1) + log("Failed to install apk $pathToApk") + exitProcess(1) } } } - .doOnSubscribe { adbDevice.log("Installing apk... pathToApk = $pathToApk") } - .doOnError { adbDevice.log("Error during installing apk: $it, pathToApk = $pathToApk") } + .doOnSubscribe { log("Installing apk... pathToApk = $pathToApk") } + .doOnError { log("Error during installing apk: $it, pathToApk = $pathToApk") } } fun AdbDevice.pullFolder(folderOnDevice: String, folderOnHostMachine: File, logErrors: Boolean, timeout: Pair = 60 to SECONDS): Single { - val adbDevice = this val pullFiles = process( - commandAndArgs = listOf(adb, "-s", adbDevice.id, "pull", folderOnDevice, folderOnHostMachine.absolutePath), + commandAndArgs = listOf(adb, "-s", id, "pull", folderOnDevice, folderOnHostMachine.absolutePath), timeout = timeout, unbufferedOutput = true ) @@ -128,15 +129,47 @@ fun AdbDevice.pullFolder(folderOnDevice: String, folderOnHostMachine: File, logE return pullFiles .ofType(Notification.Exit::class.java) .retry(3) - .doOnError { error -> if (logErrors) log("Failed to pull files from $folderOnDevice to $folderOnHostMachine failed: $error") } + .doOnError { error -> if (logErrors) log("Failed to pull files from $folderOnDevice to $folderOnHostMachine: $error") } .map { true } .onErrorReturn { false } - .toSingle() + .singleOrError() +} + +fun AdbDevice.deleteFolder(folderOnDevice: String, logErrors: Boolean, timeout: Pair = 60 to SECONDS): Single { + val deleteFolder = process( + commandAndArgs = listOf(adb, "-s", id, "shell", "rm", "-r", folderOnDevice), + timeout = timeout, + unbufferedOutput = true + ) + + return deleteFolder + .ofType(Notification.Exit::class.java) + .retry(3) + .doOnError { error -> if (logErrors) log("Failed to delete directory $folderOnDevice: $error") } + .map { true } + .onErrorReturn { false } + .singleOrError() +} + +fun AdbDevice.deleteFile(fileOnDevice: String, logErrors: Boolean, timeout: Pair = 60 to SECONDS): Single { + val deleteFile = process( + commandAndArgs = listOf(adb, "-s", id, "shell", "rm", fileOnDevice), + timeout = timeout, + unbufferedOutput = true + ) + + return deleteFile + .ofType(Notification.Exit::class.java) + .retry(3) + .doOnError { error -> if (logErrors) log("Failed to delete file $fileOnDevice: $error") } + .map { true } + .onErrorReturn { false } + .singleOrError() } -fun AdbDevice.redirectLogcatToFile(file: File): Single = Observable +fun AdbDevice.redirectLogcatToFile(file: File): Single = Single .fromCallable { file.parentFile.mkdirs() } - .flatMap { process(listOf(adb, "-s", this.id, "logcat"), redirectOutputTo = file, timeout = null) } + .flatMapObservable { process(listOf(adb, "-s", id, "logcat"), redirectOutputTo = file, timeout = null) } .ofType(Notification.Start::class.java) .doOnError { when (it) { @@ -146,4 +179,4 @@ fun AdbDevice.redirectLogcatToFile(file: File): Single = Observable } .map { it.process } .take(1) - .toSingle() + .singleOrError() diff --git a/android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt b/android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt index 4f6a731..14019e0 100644 --- a/android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt +++ b/android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt @@ -1,3 +1,4 @@ +@file:Suppress("unused") package com.gojuno.commander.android data class AdbDevice( diff --git a/android/src/test/kotlin/com/gojuno/commander/android/AdbSpec.kt b/android/src/test/kotlin/com/gojuno/commander/android/AdbSpec.kt index 03e6528..6d22a32 100644 --- a/android/src/test/kotlin/com/gojuno/commander/android/AdbSpec.kt +++ b/android/src/test/kotlin/com/gojuno/commander/android/AdbSpec.kt @@ -1,10 +1,9 @@ package com.gojuno.commander.android import com.gojuno.commander.os.Notification -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import rx.Observable +import io.reactivex.Observable +import org.spekframework.spek2.Spek +import org.spekframework.spek2.style.specification.describe class AdbSpec : Spek({ diff --git a/build.gradle b/build.gradle index f1b0ec1..0273349 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,34 @@ -apply from: 'dependencies.gradle' - buildscript { - // Gradle will not find vars defined in an external file when referring to them - // in the buildscript block, unless you link it from the buildscript block, too. - apply from: 'dependencies.gradle' - repositories { jcenter() } dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" - classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' - classpath "org.junit.platform:junit-platform-gradle-plugin:$versions.junitPlatform" - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.40" + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' } } allprojects { + apply plugin: 'kotlin' + repositories { jcenter() } - apply plugin: 'com.github.ben-manes.versions' + dependencies { + api "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + + testImplementation "org.assertj:assertj-core:3.11.1" + + testImplementation "org.spekframework.spek2:spek-dsl-jvm:2.0.5" + testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.5" + testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect" + } + + test { + useJUnitPlatform { + includeEngines 'spek2' + } + } } diff --git a/dependencies.gradle b/dependencies.gradle deleted file mode 100644 index df836f1..0000000 --- a/dependencies.gradle +++ /dev/null @@ -1,33 +0,0 @@ -ext.versions = [ - kotlin : '1.1.1', - - rxJava : '1.2.9', - jCommander : '1.66', - apacheCommonsIo : '2.5', - apacheCommonsLang: '3.5', - - junit : '4.12', - junitPlatform : '1.0.0-M3', - spek : '1.1.0', - assertJ : '3.5.2', -] - -ext.libraries = [ - os : project(':os'), - android : project(':android'), - - kotlinStd : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin", - kotlinRuntime : "org.jetbrains.kotlin:kotlin-runtime:$versions.kotlin", - kotlinReflect : "org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin", - - rxJava : "io.reactivex:rxjava:$versions.rxJava", - jCommander : "com.beust:jcommander:$versions.jCommander", - apacheCommonsIo : "commons-io:commons-io:$versions.apacheCommonsIo", - apacheCommonsLang : "org.apache.commons:commons-lang3:$versions.apacheCommonsLang", - - junit : "junit:junit:$versions.junit", - spek : "org.jetbrains.spek:spek-api:$versions.spek", - spekSubjectExtension : "org.jetbrains.spek:spek-subject-extension:$versions.spek", - spekJunitPlatformEngine: "org.jetbrains.spek:spek-junit-platform-engine:$versions.spek", - assertJ : "org.assertj:assertj-core:$versions.assertJ", -] diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4429f0e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +group=com.gojuno.commander +version=0.2.0 diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle index 7aea307..0c8c9a1 100644 --- a/gradle/publishing.gradle +++ b/gradle/publishing.gradle @@ -1,4 +1,3 @@ -apply plugin: 'maven' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.bintray' @@ -12,9 +11,7 @@ def gitTag() { return tag } -def projectVersion() { - def tag = gitTag() - +def projectVersion(tag) { if (tag.startsWith('v')) { return tag.substring(1) } else if (tag.isEmpty()) { @@ -25,40 +22,29 @@ def projectVersion() { } def validateTagAndVersion() { - if (gitTag().isEmpty()) { + def gitTag = gitTag() + def tagVersion = projectVersion(gitTag) + + if (gitTag.isEmpty()) { throw new IllegalStateException('Publishing is not allowed because current commit has no tag') } - if (projectVersion().isEmpty()) { + if (tagVersion.isEmpty()) { throw new IllegalStateException('Publishing is not allowed because current projectVersion is empty') } -} -def pomConfig = { - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - developers { - developer { - id 'gojuno' - name 'Juno Inc.' - email 'opensource@gojuno.com' - } + if (tagVersion != project.version) { + throw new IllegalStateException('Publishing not allowed because current tag version does not match version declared in gradle.properties') } } - task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } @@ -78,16 +64,23 @@ publishing { artifact sourcesJar artifact javadocJar - groupId 'com.gojuno.commander' - artifactId project.name - version projectVersion() - - pom.withXml { - def root = asNode() - root.appendNode('description', project.description) - root.appendNode('name', project.name) - root.appendNode('url', 'https://github.com/gojuno/commander') - root.children().last() + pomConfig + pom { + url = 'https://github.com/gojuno/commander' + description = project.description + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' + } + } + developers { + developer { + id = 'gojuno' + name = 'Juno Inc.' + email = 'opensource@gojuno.com' + } + } } } } @@ -107,7 +100,7 @@ bintray { publications = ['CommanderPublication'] version { - name = projectVersion() + name = project.version vcsTag = gitTag() gpg { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2b265cc..7feb879 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59105ec..5b307ef 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 05 19:47:52 MSK 2017 +#Mon Jul 01 23:35:14 MDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip diff --git a/os/build.gradle b/os/build.gradle index 18ffc5f..ccf1464 100644 --- a/os/build.gradle +++ b/os/build.gradle @@ -1,27 +1,7 @@ -apply plugin: 'kotlin' -apply plugin: 'org.junit.platform.gradle.plugin' -apply from: '../gradle/publishing.gradle' +description = "Functions to work with processes and files on different Operating Systems." dependencies { - compile libraries.kotlinStd - compile libraries.kotlinRuntime - compile libraries.kotlinReflect - compile libraries.rxJava + api "io.reactivex.rxjava2:rxjava:2.2.10" } -dependencies { - testCompile libraries.spek - testCompile libraries.spekSubjectExtension - testCompile libraries.spekJunitPlatformEngine - testCompile libraries.assertJ -} - -junitPlatform { - platformVersion = versions.junitPlatform - - filters { - engines { - include 'spek' - } - } -} +apply from: '../gradle/publishing.gradle' \ No newline at end of file diff --git a/os/gradle.properties b/os/gradle.properties deleted file mode 100644 index e88498c..0000000 --- a/os/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -name=os -description=Functions to work with processes and files on different Operating Systems. diff --git a/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt b/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt index 5bec24f..5fb68ba 100644 --- a/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt +++ b/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt @@ -3,11 +3,13 @@ package com.gojuno.commander.os import com.gojuno.commander.os.Os.Linux import com.gojuno.commander.os.Os.Mac import com.gojuno.commander.os.Os.Windows -import rx.Emitter.BackpressureMode -import rx.Observable -import rx.schedulers.Schedulers.io +import io.reactivex.Observable +import io.reactivex.ObservableEmitter +import io.reactivex.schedulers.Schedulers.io import java.io.File -import java.util.* +import java.util.Date +import java.util.Random +import java.util.Locale import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.SECONDS import java.util.concurrent.TimeoutException @@ -29,83 +31,81 @@ fun process( unbufferedOutput: Boolean = false, print: Boolean = false, destroyOnUnsubscribe: Boolean = false -): Observable = Observable.create( - { emitter -> - if (print) { - log("\nRun: $commandAndArgs") - } +): Observable = Observable.create { emitter: ObservableEmitter -> + if (print) { + log("\nRun: $commandAndArgs") + } - val outputFile = when { - redirectOutputTo == null || redirectOutputTo.isDirectory -> { - prepareOutputFile(redirectOutputTo, keepOutputOnExit) - } - else -> redirectOutputTo - } + val outputFile = when { + redirectOutputTo == null || redirectOutputTo.isDirectory -> { + prepareOutputFile(redirectOutputTo, keepOutputOnExit) + } + else -> redirectOutputTo + } - outputFile.apply { parentFile?.mkdirs() } + outputFile.apply { parentFile?.mkdirs() } - if (print) { - log("$commandAndArgs\n, outputFile = $outputFile") - } + if (print) { + log("$commandAndArgs\n, outputFile = $outputFile") + } - val command: List = when (unbufferedOutput) { - false -> commandAndArgs - true -> when (os()) { - // Some programs, in particular "emulator" do not always flush output - // after printing so we have to force unbuffered mode to make sure - // that output will be available for consuming. - Linux -> listOf("script", outputFile.absolutePath, "--flush", "-c", commandAndArgs.joinToString(separator = " ")) - Mac -> listOf("script", "-F", outputFile.absolutePath, *commandAndArgs.toTypedArray()) - Windows -> commandAndArgs - } - } + val command: List = when (unbufferedOutput) { + false -> commandAndArgs + true -> when (os()) { + // Some programs, in particular "emulator" do not always flush output + // after printing so we have to force unbuffered mode to make sure + // that output will be available for consuming. + Linux -> listOf("script", outputFile.absolutePath, "--flush", "-c", commandAndArgs.joinToString(separator = " ")) + Mac -> listOf("script", "-F", outputFile.absolutePath, *commandAndArgs.toTypedArray()) + Windows -> commandAndArgs + } + } - val process: Process = ProcessBuilder(command) - .redirectErrorStream(true) - .let { - when { - unbufferedOutput && os() !== Windows -> { - it.redirectOutput(os().nullDeviceFile()) - } - else -> it.redirectOutput(ProcessBuilder.Redirect.to(outputFile)) - } - } - .start() - - if (destroyOnUnsubscribe) { - emitter.setCancellation { - process.destroy() + val process: Process = ProcessBuilder(command) + .redirectErrorStream(true) + .let { + when { + unbufferedOutput && os() !== Windows -> { + it.redirectOutput(os().nullDeviceFile()) } + else -> it.redirectOutput(ProcessBuilder.Redirect.to(outputFile)) } + } + .start() + + if (destroyOnUnsubscribe) { + emitter.setCancellable { + process.destroy() + } + } - emitter.onNext(Notification.Start(process, outputFile)) + emitter.onNext(Notification.Start(process, outputFile)) - if (timeout == null) { - process.waitFor() - } else { - if (process.waitFor(timeout.first.toLong(), timeout.second).not()) { - throw TimeoutException("Process $command timed out ${timeout.first} ${timeout.second} waiting for exit code ${outputFile.readText()}") - } - } + if (timeout == null) { + process.waitFor() + } else { + if (process.waitFor(timeout.first.toLong(), timeout.second).not()) { + throw TimeoutException("Process $command timed out ${timeout.first} ${timeout.second} waiting for exit code ${outputFile.readText()}") + } + } - val exitCode = process.exitValue() + val exitCode = process.exitValue() - if (print) { - log("Exit code $exitCode: $commandAndArgs,\noutput = \n${outputFile.readText()}") - } + if (print) { + log("Exit code $exitCode: $commandAndArgs,\noutput = \n${outputFile.readText()}") + } - when (exitCode) { - 0 -> { - emitter.onNext(Notification.Exit(outputFile)) - emitter.onCompleted() - } - else -> { - emitter.onError(IllegalStateException("Process $command exited with non-zero code $exitCode ${outputFile.readText()}")) - } - } - }, BackpressureMode.LATEST -) - .subscribeOn(io()) // Prevent subscriber thread from unnecessary blocking. + when (exitCode) { + 0 -> { + emitter.onNext(Notification.Exit(outputFile)) + emitter.onComplete() + } + else -> { + emitter.onError(IllegalStateException("Process $command exited with non-zero code $exitCode ${outputFile.readText()}")) + } + } +} + .subscribeOn(io()) // Prevent subscriber thread from unnecessary blocking. .observeOn(io()) // Allow to wait for process exit code. private fun prepareOutputFile(parent: File?, keepOnExit: Boolean): File = Random() diff --git a/os/src/test/kotlin/com/gojuno/commander/os/ProcessesSpec.kt b/os/src/test/kotlin/com/gojuno/commander/os/ProcessesSpec.kt index 0ee5850..d99b78e 100644 --- a/os/src/test/kotlin/com/gojuno/commander/os/ProcessesSpec.kt +++ b/os/src/test/kotlin/com/gojuno/commander/os/ProcessesSpec.kt @@ -1,11 +1,8 @@ package com.gojuno.commander.os import org.assertj.core.api.Assertions.assertThat -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.api.dsl.on -import java.io.File +import org.spekframework.spek2.Spek +import org.spekframework.spek2.style.specification.describe import java.util.concurrent.TimeUnit.MINUTES import java.util.concurrent.TimeUnit.SECONDS @@ -22,7 +19,7 @@ class ProcessesSpec : Spek({ describe("nanosToHumanReadableTime") { - on("convert 1 second") { + context("convert 1 second") { val result by memoized { SECONDS.toNanos(1).nanosToHumanReadableTime() } @@ -31,16 +28,16 @@ class ProcessesSpec : Spek({ } } - on("convert 59 seconds") { + context("convert 59 seconds") { val result by memoized { SECONDS.toNanos(59).nanosToHumanReadableTime() } - it("converts it to 59 second") { + it("converts it to 59 seconds") { assertThat(result).isEqualTo("59 seconds") } } - on("convert 60 seconds") { + context("convert 60 seconds") { val result by memoized { SECONDS.toNanos(60).nanosToHumanReadableTime() } @@ -49,7 +46,7 @@ class ProcessesSpec : Spek({ } } - on("convert 61 seconds") { + context("convert 61 seconds") { val result by memoized { SECONDS.toNanos(61).nanosToHumanReadableTime() } @@ -58,16 +55,16 @@ class ProcessesSpec : Spek({ } } - on("convert 62 seconds") { + context("convert 62 seconds") { val result by memoized { SECONDS.toNanos(62).nanosToHumanReadableTime() } - it("converts it to 1 minute 2 second") { + it("converts it to 1 minute 2 seconds") { assertThat(result).isEqualTo("1 minute 2 seconds") } } - on("convert 60 minutes") { + context("convert 60 minutes") { val result by memoized { MINUTES.toNanos(60).nanosToHumanReadableTime() } @@ -76,7 +73,7 @@ class ProcessesSpec : Spek({ } } - on("convert 61 minutes") { + context("convert 61 minutes") { val result by memoized { MINUTES.toNanos(61).nanosToHumanReadableTime() }