Skip to content

Commit c574ce7

Browse files
Issues reported by sonar
1 parent 5b603f0 commit c574ce7

18 files changed

+50
-57
lines changed

src/main/java/net/masterthought/cucumber/ReportBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.nio.charset.StandardCharsets;
1313
import java.util.List;
1414

15-
import com.fasterxml.jackson.core.StreamReadConstraints;
1615
import com.fasterxml.jackson.databind.JsonMappingException;
1716
import com.fasterxml.jackson.databind.ObjectMapper;
1817
import com.fasterxml.jackson.databind.ObjectWriter;

src/main/java/net/masterthought/cucumber/reducers/ElementComparator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package net.masterthought.cucumber.reducers;
22

3-
import net.masterthought.cucumber.json.Element;
4-
import org.apache.commons.lang3.StringUtils;
5-
63
import java.util.Comparator;
74

5+
import net.masterthought.cucumber.json.Element;
6+
import org.apache.commons.lang3.Strings;
7+
88
/**
99
* Compares two elements and shows if they have the same Id for scenario type
1010
* or they are on the same line if it's a background.
@@ -33,6 +33,6 @@ public int compare(Element element1, Element element2) {
3333

3434
private boolean hasSameType(Element element1, Element element2) {
3535
return element1 != null && element2 != null &&
36-
StringUtils.equalsIgnoreCase(element1.getType(), element2.getType());
36+
Strings.CI.equals(element1.getType(), element2.getType());
3737
}
3838
}

src/main/java/net/masterthought/cucumber/util/StepNameFormatter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package net.masterthought.cucumber.util;
22

3-
import org.apache.commons.text.StringEscapeUtils;
3+
import net.masterthought.cucumber.json.support.Argument;
44
import org.apache.commons.lang3.ArrayUtils;
55
import org.apache.commons.lang3.StringUtils;
6-
7-
import net.masterthought.cucumber.json.support.Argument;
6+
import org.apache.commons.text.StringEscapeUtils;
87

98
public class StepNameFormatter {
109

@@ -46,7 +45,7 @@ private static void surroundArguments(Argument[] arguments, String preArgument,
4645
}
4746

4847
private static boolean isValidArgument(Argument argument) {
49-
return argument.getOffset() != null && argument.getVal().length() > 0;
48+
return !(argument.getOffset() == null || argument.getVal().isEmpty());
5049
}
5150

5251
private static void escape(String[] chars) {

src/test/java/net/masterthought/cucumber/ReportGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
public abstract class ReportGenerator {
1818

19-
public final static String JSON_DIRECTORY = "json/";
20-
public final static String CLASSIFICATIONS_DIRECTORY = "classifications/";
19+
public static final String JSON_DIRECTORY = "json/";
20+
public static final String CLASSIFICATIONS_DIRECTORY = "classifications/";
2121

2222
protected static final String SAMPLE_JSON = "sample.json";
2323
protected static final String CUCUMBER_TIMESTAMPED_JSON = "timestamped/all-last-failed.json";
@@ -54,6 +54,7 @@ public ReportGenerator() {
5454
configuration = new Configuration(reportDirectory, projectName);
5555
configuration.setSortingMethod(SortingMethod.ALPHABETICAL);
5656
configuration.getEmbeddingDirectory().mkdirs();
57+
configuration.setBuildNumber("123321");
5758
} catch (URISyntaxException e) {
5859
throw new ValidationException(e);
5960
}

src/test/java/net/masterthought/cucumber/TrendsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void addBuild_OnMissingDataForSteps_FillsMissingDataForSteps() {
5555
trends.addBuild("buildName", result);
5656
final String[] buildNumbers = new String[]{"a", "b", "e"};
5757
Whitebox.setInternalState(trends, "buildNumbers", buildNumbers);
58-
58+
5959
// when
6060
trends.addBuild("the build!", result);
6161

@@ -122,7 +122,7 @@ void copyLastElements_OnBigLimit_ReturnsPassedIntArray() throws Exception {
122122
int[] limitedArray = Whitebox.invokeMethod(Trends.class, "copyLastElements", array, limit);
123123

124124
// then
125-
assertThat(limitedArray).isSameAs(array);
125+
assertThat(limitedArray).containsExactly(array);
126126
}
127127

128128
@Test
@@ -136,7 +136,7 @@ void copyLastElements_OnBigLimit_ReturnsPassedLongArray() throws Exception {
136136
long[] limitedArray = Whitebox.invokeMethod(Trends.class, "copyLastElements", array, limit);
137137

138138
// then
139-
assertThat(limitedArray).isSameAs(array);
139+
assertThat(limitedArray).containsExactly(array);
140140
}
141141

142142
@Test
@@ -150,7 +150,7 @@ void copyLastElements_OnBigLimit_ReturnsPassedStringArray() throws Exception {
150150
String[] limitedArray = Whitebox.invokeMethod(Trends.class, "copyLastElements", array, limit);
151151

152152
// then
153-
assertThat(limitedArray).isSameAs(array);
153+
assertThat(limitedArray).containsExactly(array);
154154
}
155155

156156
@Test

src/test/java/net/masterthought/cucumber/generators/OverviewReportTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ void incDuration_AddsDuration() {
148148

149149
// given
150150
long offset = 5555555;
151-
OverviewReport RefReport = buildSampleReport();
151+
OverviewReport refReport = buildSampleReport();
152152
OverviewReport report = buildSampleReport();
153153

154154
// when
155155
report.incDurationBy(offset);
156156

157157
// then
158-
assertThat(report.getDuration()).isEqualTo(RefReport.getDuration() + offset);
158+
assertThat(report.getDuration()).isEqualTo(refReport.getDuration() + offset);
159159
}
160160

161161
@Test
@@ -185,7 +185,7 @@ void getName_ThrowsException() {
185185
OverviewReport report = buildSampleReport();
186186

187187
// when & then
188-
assertThatThrownBy(() -> report.getName()).
188+
assertThatThrownBy(report::getName).
189189
isInstanceOf(NotImplementedException.class);
190190
}
191191

@@ -196,7 +196,7 @@ void getStatus_ThrowsException() {
196196
OverviewReport report = buildSampleReport();
197197

198198
// when & then
199-
assertThatThrownBy(() -> report.getStatus())
199+
assertThatThrownBy(report::getStatus)
200200
.isInstanceOf(NotImplementedException.class);
201201
}
202202

src/test/java/net/masterthought/cucumber/generators/integrations/ErrorPageIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ void generatePage_generatesTitle() {
2121
// given
2222
setUpWithJson(SAMPLE_JSON);
2323
page = new ErrorPage(reportResult, configuration, cause, jsonReports);
24-
final String titleValue = String.format("Cucumber Reports - Error Page");
24+
final String titleValue = String.format("Cucumber Reports (no %s) - Error Page",
25+
configuration.getBuildNumber());
2526

2627
// when
2728
page.generatePage();

src/test/java/net/masterthought/cucumber/generators/integrations/FeatureReportPageIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.masterthought.cucumber.generators.integrations;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import java.io.File;
46
import java.util.Arrays;
57
import java.util.Collections;
@@ -30,8 +32,6 @@
3032
import org.apache.commons.lang3.StringUtils;
3133
import org.junit.jupiter.api.Test;
3234

33-
import static org.assertj.core.api.Assertions.assertThat;
34-
3535
/**
3636
* @author Damian Szczepanik (damianszczepanik@github)
3737
*/
@@ -44,7 +44,8 @@ void generatePage_generatesTitle() {
4444
setUpWithJson(SAMPLE_JSON);
4545
final Feature feature = features.get(0);
4646
page = new FeatureReportPage(reportResult, configuration, feature);
47-
final String titleValue = String.format("Cucumber Reports - Feature: %s", feature.getName());
47+
final String titleValue = String.format("Cucumber Reports (no %s) - Feature: %s",
48+
configuration.getBuildNumber(), feature.getName());
4849

4950
// when
5051
page.generatePage();

src/test/java/net/masterthought/cucumber/generators/integrations/PageIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.io.File;
66
import java.util.Locale;
77

8-
import org.junit.jupiter.api.BeforeEach;
9-
import org.junit.jupiter.api.Test;
108
import net.masterthought.cucumber.generators.FailuresOverviewPage;
119
import net.masterthought.cucumber.generators.FeaturesOverviewPage;
1210
import net.masterthought.cucumber.generators.StepsOverviewPage;
@@ -19,6 +17,8 @@
1917
import net.masterthought.cucumber.generators.integrations.helpers.TableRowAssertion;
2018
import net.masterthought.cucumber.generators.integrations.helpers.WebAssertion;
2119
import net.masterthought.cucumber.presentation.PresentationMode;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
2222

2323
/**
2424
* @author Damian Szczepanik (damianszczepanik@github)
@@ -75,7 +75,7 @@ void generatePage_onJenkinsConfiguration_generatesAllItemsInNaviBar() {
7575
navigation.hasPluginName();
7676
assertThat(navigation.getNaviBarLinks()).hasSize(7);
7777

78-
menuItems[0].hasLinkToJenkins(configuration);
78+
menuItems[0].hasLinkToJenkins();
7979
menuItems[1].hasLinkToPreviousResult(configuration, page.getWebPage());
8080
menuItems[2].hasLinkToLastResult(configuration, page.getWebPage());
8181
}
@@ -118,10 +118,10 @@ void generatePage_onDefaultConfiguration_generatesSummaryTable() {
118118
BuildInfoAssertion buildInfo = document.getBuildInfo();
119119

120120
TableRowAssertion headValues = buildInfo.getHeaderRow();
121-
headValues.hasExactValues("Project", "Date");
121+
headValues.hasExactValues("Project", "Number", "Date");
122122

123123
assertThat(buildInfo.getProjectName()).isEqualTo(configuration.getProjectName());
124-
buildInfo.hasBuildDate(false);
124+
buildInfo.hasBuildDate(true);
125125
}
126126

127127
@Test

src/test/java/net/masterthought/cucumber/generators/integrations/TagReportPageIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ void generatePage_generatesTitle() {
2424
setUpWithJson(SAMPLE_JSON);
2525
final TagObject tag = tags.get(0);
2626
page = new TagReportPage(reportResult, configuration, tag);
27-
final String titleValue = String.format("Cucumber Reports - Tag: %s", tag.getName());
27+
final String titleValue = String.format("Cucumber Reports (no %s) - Tag: %s",
28+
configuration.getBuildNumber(), tag.getName());
2829

2930
// when
3031
page.generatePage();

0 commit comments

Comments
 (0)