-
Notifications
You must be signed in to change notification settings - Fork 31
Add unit test for AddedVersusDeletedLinesTrendChart
#351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for AddedVersusDeletedLinesTrendChart
#351
Conversation
AddedVersusDeletedLinesTrendChart builder = new AddedVersusDeletedLinesTrendChart(); | ||
|
||
Iterable<BuildResult<CommitStatisticsBuildAction>> buildResultsStub = createBuildResultsStub(); | ||
ChartModelConfiguration chartModelConfigurationStub = createConfiguration(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use simple dummy object if possible:
ChartModelConfiguration chartModelConfigurationStub = createConfiguration(); | |
ChartModelConfiguration chartModelConfigurationStub = new ChartModelConfiguration(); |
private Iterable<BuildResult<CommitStatisticsBuildAction>> createBuildResultsStub() { | ||
return new Iterable<BuildResult<CommitStatisticsBuildAction>>() { | ||
@Override | ||
public Iterator<BuildResult<CommitStatisticsBuildAction>> iterator() { | ||
return null; | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier to replace with something like (see https://github.com/jenkinsci/forensics-api-plugin/blob/master/src/test/java/io/jenkins/plugins/forensics/miner/FilesCountTrendChartTest.java for a reference):
private BuildResult<CommitStatisticsBuildAction> createResult(final int buildNumber, final int added, final int deleted) {
CommitStatisticsBuildAction action = mock(CommitStatisticsBuildAction.class);
CommitStatistics commitStatistics = mock(CommitStatistics.class);
when(commitStatistics.getAddedLines()).thenReturn(added);
when(commitStatistics.getDeletedLines()).thenReturn(deleted);
when(action.getCommitStatistics()).thenReturn(commitStatistics);
Build build = new Build(buildNumber);
return new BuildResult<>(build, action);
}
void shouldCreate() { | ||
AddedVersusDeletedLinesTrendChart builder = new AddedVersusDeletedLinesTrendChart(); | ||
|
||
Iterable<BuildResult<CommitStatisticsBuildAction>> buildResultsStub = createBuildResultsStub(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced by a simple list:
List<BuildResult<CommitStatisticsBuildAction>> results = new ArrayList<>();
results.add(createResult(2, 20, 10));
results.add(createResult(1, 30, 25));
SeriesBuilder seriesBuilderStub = createSeriesBuilderStub(); | ||
LinesDataSet linesDataSet = mock(LinesDataSet.class); | ||
|
||
when(seriesBuilderStub.createDataSet(chartModelConfigurationStub, buildResultsStub)) | ||
.thenReturn(linesDataSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required anymore
assertThat(lineChartModel) | ||
.satisfies(model -> { | ||
assertThat(model.getSeries()).size().isEqualTo(2); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(lineChartModel) | |
.satisfies(model -> { | |
assertThat(model.getSeries()).size().isEqualTo(2); | |
}); | |
assertThat(lineChartModel.getSeries()).hasSize(2); |
.satisfies(model -> { | ||
assertThat(model.getSeries()).size().isEqualTo(2); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this object is converted to JSON it might be easier to validate using JSON assertions as in https://github.com/jenkinsci/forensics-api-plugin/blob/master/src/test/java/io/jenkins/plugins/forensics/miner/FilesCountTrendChartTest.java
.satisfies(model -> { | ||
assertThat(model.getSeries()).size().isEqualTo(2); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this object is converted to JSON it might be easier to validate using JSON assertions as in https://github.com/jenkinsci/forensics-api-plugin/blob/master/src/test/java/io/jenkins/plugins/forensics/miner/FilesCountTrendChartTest.java
Codecov Report
@@ Coverage Diff @@
## master #351 +/- ##
============================================
+ Coverage 50.04% 55.71% +5.67%
- Complexity 253 271 +18
============================================
Files 42 42
Lines 1093 1093
Branches 92 92
============================================
+ Hits 547 609 +62
+ Misses 510 447 -63
- Partials 36 37 +1
Continue to review full report at Codecov.
|
AddedVersusDeletedLinesTrendChart
Uh oh!
There was an error while loading. Please reload this page.