diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt index c223ccf..40077a7 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt @@ -20,6 +20,7 @@ package de.staropensource.engine.base.utility import de.staropensource.engine.base.Engine.Companion.logger +import de.staropensource.engine.base.exception.VerificationFailedException import de.staropensource.engine.base.exception.io.IOAccessException import de.staropensource.engine.base.implementable.stream.ReadStream import de.staropensource.engine.base.implementable.stream.Stream @@ -277,6 +278,81 @@ class Process { } + // -----> Verification + /** + * Verifies that this [Process] + * has the same PID as specified. + * + * @param pid pid to compare + * @return this instance + * @throws VerificationFailedException if verification fails + * @since v1-alpha10 + */ + fun verifyPidEquals(pid: Long): Process { + if (getPid() != pid) + throw VerificationFailedException("Expected that PID ${getPid()} of Process[${hashCode()}] equals specified PID ${pid}") + return this + } + + /** + * Verifies that this [Process] + * is alive and running. + * + * @return this instance + * @throws VerificationFailedException if verification fails + * @since v1-alpha10 + */ + fun verifyAlive(): Process { + if (!isAlive()) + throw VerificationFailedException("Expected that process ${getPid()} is alive") + return this + } + + /** + * Verifies that this [Process] + * is not alive and running. + * + * @return this instance + * @throws VerificationFailedException if verification fails + * @since v1-alpha10 + */ + fun verifyNotAlive(): Process { + if (isAlive()) + throw VerificationFailedException("Expected that process ${getPid()} is not alive") + return this + } + + /** + * Verifies that this [Process] + * has been launched with + * a fresh environment. + * + * @return this instance + * @throws VerificationFailedException if verification fails + * @since v1-alpha10 + */ + fun verifyLaunchedWithFreshEnvironment(): Process { + if (!launchedWithFreshEnvironment) + throw VerificationFailedException("Expected that process ${getPid()} was launched with a fresh environment") + return this + } + + /** + * Verifies that this [Process] + * has not been launched with + * a fresh environment. + * + * @return this instance + * @throws VerificationFailedException if verification fails + * @since v1-alpha10 + */ + fun verifyNotLaunchedWithFreshEnvironment(): Process { + if (launchedWithFreshEnvironment) + throw VerificationFailedException("Expected that process ${getPid()} was not launched with a fresh environment") + return this + } + + // -----> Inner classes /** * Used for the [standardInput]