Created
January 15, 2019 18:33
-
-
Save double16/6ba77c57e502c6972b81daa1c000ec0a to your computer and use it in GitHub Desktop.
Gradle ExecAction mock for Spock tests
This file contains hidden or 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
class MockExecAction extends DefaultExecAction { | |
int exitValue = 0 | |
String output = '' | |
MockExecAction() { | |
super(null, null, null) | |
} | |
@Override | |
ExecResult execute() { | |
standardOutput.write(output.getBytes('UTF-8')) | |
ExecResult result = new ExecResult() { | |
@Override | |
int getExitValue() { | |
MockExecAction.this.exitValue | |
} | |
@Override | |
ExecResult assertNormalExitValue() throws ExecException { | |
if (exitValue != 0) { | |
throw new ExecException("Command exited with ${exitValue}: ${getCommandLine().join(' ')}") | |
} | |
this | |
} | |
@Override | |
ExecResult rethrowFailure() throws ExecException { | |
assertNormalExitValue() | |
} | |
} | |
result.assertNormalExitValue() | |
result | |
} | |
} |
This file contains hidden or 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
class MockExecActionFactory implements ExecActionFactory { | |
MockExecAction mockExecAction = new MockExecAction() | |
@Override | |
ExecAction newExecAction() { | |
mockExecAction | |
} | |
@Override | |
JavaExecAction newJavaExecAction() { | |
return null // TODO: | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment