Add verification methods to Process
This commit is contained in:
parent
1cf6c9ac41
commit
c3223f0add
1 changed files with 76 additions and 0 deletions
|
@ -20,6 +20,7 @@
|
||||||
package de.staropensource.engine.base.utility
|
package de.staropensource.engine.base.utility
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine.Companion.logger
|
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.exception.io.IOAccessException
|
||||||
import de.staropensource.engine.base.implementable.stream.ReadStream
|
import de.staropensource.engine.base.implementable.stream.ReadStream
|
||||||
import de.staropensource.engine.base.implementable.stream.Stream
|
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
|
// -----> Inner classes
|
||||||
/**
|
/**
|
||||||
* Used for the [standardInput]
|
* Used for the [standardInput]
|
||||||
|
|
Loading…
Reference in a new issue