forked from jenkinsci/warnings-ng-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jenkinsci#662 from naveennvrgup/MatrixBridge-tests
Unittest for MatrixBridge
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
plugin/src/test/java/io/jenkins/plugins/analysis/core/steps/MatrixBridgeTest.java
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,59 @@ | ||
package io.jenkins.plugins.analysis.core.steps; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import hudson.Launcher; | ||
import hudson.matrix.MatrixAggregator; | ||
import hudson.matrix.MatrixBuild; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.model.BuildListener; | ||
import hudson.util.DescribableList; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* Tests the class {@link MatrixBridge}. | ||
* | ||
* @author Naveen Sundar | ||
*/ | ||
class MatrixBridgeTest { | ||
|
||
@Test | ||
void constructMatrixAggregatorWithoutRecorder() { | ||
MatrixBuild build = createBuild(false); | ||
MatrixAggregator aggregator = createAggregator(build); | ||
|
||
assertThat(aggregator).isNull(); | ||
} | ||
|
||
@Test | ||
void constructMatrixAggregatorWithRecorder() { | ||
MatrixBuild build = createBuild(true); | ||
MatrixAggregator aggregator = createAggregator(build); | ||
|
||
assertThat(aggregator).isNotNull(); | ||
} | ||
|
||
private MatrixBuild createBuild(final boolean withIssueRecorder) { | ||
MatrixBuild build = mock(MatrixBuild.class); | ||
MatrixProject matrixProject = mock(MatrixProject.class); | ||
DescribableList describableList = mock(DescribableList.class); | ||
|
||
when(build.getParent()).thenReturn(matrixProject); | ||
when(matrixProject.getPublishersList()).thenReturn(describableList); | ||
|
||
if (withIssueRecorder) { | ||
when(describableList.get(IssuesRecorder.class)).thenReturn(mock(IssuesRecorder.class)); | ||
} | ||
else { | ||
when(describableList.get(IssuesRecorder.class)).thenReturn(null); | ||
} | ||
|
||
return build; | ||
} | ||
|
||
private MatrixAggregator createAggregator(final MatrixBuild build) { | ||
return new MatrixBridge().createAggregator(build, mock(Launcher.class), mock(BuildListener.class)); | ||
} | ||
} |