Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Finish JENKINS-41947
- Loading branch information
Showing
12 changed files
with
441 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package jenkins.plugins.nodejs; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import org.powermock.api.mockito.PowerMockito; | ||
|
||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.TaskListener; | ||
import jenkins.plugins.nodejs.tools.NodeJSInstallation; | ||
|
||
/* package */ final class CIBuilderHelper { | ||
|
||
public static interface Verifier { | ||
void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception; | ||
} | ||
|
||
public static NodeJSCommandInterpreter createMock(String command, NodeJSInstallation installation, String configId) { | ||
return createMock(command, installation, configId, null); | ||
} | ||
|
||
public static NodeJSCommandInterpreter createMock(String command, NodeJSInstallation installation, String configId, | ||
Verifier verifier) { | ||
MockCommandInterpreterBuilder spy = PowerMockito.spy(new MockCommandInterpreterBuilder(command, installation.getName(), configId)); | ||
doReturn(installation).when(spy).getNodeJS(); | ||
doReturn(new NodeJSCommandInterpreter.NodeJsDescriptor()).when(spy).getDescriptor(); | ||
spy.setVerifier(verifier); | ||
return spy; | ||
} | ||
|
||
static class MockCommandInterpreterBuilder extends NodeJSCommandInterpreter { | ||
|
||
// transient to ensure serialisation | ||
private transient CIBuilderHelper.Verifier verifier; | ||
|
||
private MockCommandInterpreterBuilder(String command, String nodeJSInstallationName, String configId) { | ||
super(command, nodeJSInstallationName, configId); | ||
} | ||
|
||
@Override | ||
protected boolean internalPerform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) | ||
throws InterruptedException { | ||
super.internalPerform(build, launcher, listener); | ||
if (verifier != null) { | ||
try { | ||
verifier.verify(build, launcher, listener); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private void setVerifier(Verifier verifier) { | ||
this.verifier = verifier; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.