From 831619722b05c2cdd5a8550c1620c1774bb21891 Mon Sep 17 00:00:00 2001 From: Jitendra Singh2 <138148209+jit3pam@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:38:45 +0000 Subject: [PATCH 1/6] Change the visibility of the reportParser field: --- src/main/java/net/masterthought/cucumber/ReportBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/masterthought/cucumber/ReportBuilder.java b/src/main/java/net/masterthought/cucumber/ReportBuilder.java index 543da5d0b..c3c638f94 100755 --- a/src/main/java/net/masterthought/cucumber/ReportBuilder.java +++ b/src/main/java/net/masterthought/cucumber/ReportBuilder.java @@ -53,7 +53,7 @@ public class ReportBuilder { private static final ObjectMapper mapper = new ObjectMapper(); private ReportResult reportResult; - private final ReportParser reportParser; + protected ReportParser reportParser; private Configuration configuration; private List jsonFiles; From af2ad6bf739c273d1c44e98288b51494221a3a56 Mon Sep 17 00:00:00 2001 From: Jitendra_Singh2 Date: Thu, 14 Nov 2024 22:30:05 +0530 Subject: [PATCH 2/6] Revert "Change the visibility of the reportParser field:" This reverts commit 831619722b05c2cdd5a8550c1620c1774bb21891. --- src/main/java/net/masterthought/cucumber/ReportBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/masterthought/cucumber/ReportBuilder.java b/src/main/java/net/masterthought/cucumber/ReportBuilder.java index c3c638f94..543da5d0b 100755 --- a/src/main/java/net/masterthought/cucumber/ReportBuilder.java +++ b/src/main/java/net/masterthought/cucumber/ReportBuilder.java @@ -53,7 +53,7 @@ public class ReportBuilder { private static final ObjectMapper mapper = new ObjectMapper(); private ReportResult reportResult; - protected ReportParser reportParser; + private final ReportParser reportParser; private Configuration configuration; private List jsonFiles; From 4da9a7ecd16cd78a743eb141ec568d645b79d606 Mon Sep 17 00:00:00 2001 From: Jitendra_Singh2 Date: Thu, 14 Nov 2024 22:45:43 +0530 Subject: [PATCH 3/6] use getter and setters for reportParser field in ReportBuilder and add unit tests --- .../masterthought/cucumber/ReportBuilder.java | 17 +++++++- .../cucumber/ReportBuilderTest.java | 41 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/masterthought/cucumber/ReportBuilder.java b/src/main/java/net/masterthought/cucumber/ReportBuilder.java index 543da5d0b..41300b323 100755 --- a/src/main/java/net/masterthought/cucumber/ReportBuilder.java +++ b/src/main/java/net/masterthought/cucumber/ReportBuilder.java @@ -53,8 +53,7 @@ public class ReportBuilder { private static final ObjectMapper mapper = new ObjectMapper(); private ReportResult reportResult; - private final ReportParser reportParser; - + private ReportParser reportParser; private Configuration configuration; private List jsonFiles; @@ -71,6 +70,20 @@ public ReportBuilder(List jsonFiles, Configuration configuration) { reportParser = new ReportParser(configuration); } + public ReportBuilder(List jsonFiles, Configuration configuration, ReportParser reportParser){ + this.jsonFiles = jsonFiles; + this.configuration = configuration; + setReportParser(reportParser); + } + + public ReportParser getReportParser() { + return reportParser; + } + + public void setReportParser(ReportParser reportParser) { + this.reportParser = reportParser; + } + /** * Parses provided files and generates the report. When generating process fails * report with information about error is provided. diff --git a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java index 1fff9618b..d14f1f22f 100644 --- a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java +++ b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java @@ -62,6 +62,47 @@ void ReportBuilder_storesFilesAndConfiguration() { assertThat(assignedConfiguration).isSameAs(configuration); } + @Test + void ReportBuilder_usesCustomReportParser(){ + // given + final List jsonFiles = new ArrayList<>(); + final Configuration configuration = new Configuration(null, null); + final ReportParser reportParser = new ReportParser(configuration); + + // when + ReportBuilder builder = new ReportBuilder(jsonFiles, configuration, reportParser); + + // then + List assignedJsonReports = Whitebox.getInternalState(builder, "jsonFiles"); + Configuration assignedConfiguration = Whitebox.getInternalState(builder, "configuration"); + ReportParser assignedReportParser = Whitebox.getInternalState(builder, "reportParser"); + + assertThat(assignedJsonReports).isSameAs(jsonFiles); + assertThat(assignedConfiguration).isSameAs(configuration); + assertThat(assignedReportParser).isSameAs(reportParser); + } + + @Test + void ReportBuilder_setsAndGetsCustomReportParser(){ + // given + final List jsonFiles = new ArrayList<>(); + final Configuration configuration = new Configuration(null, null); + final ReportParser reportParser = new ReportParser(configuration); + + // when + ReportBuilder builder = new ReportBuilder(jsonFiles, configuration); + builder.setReportParser(reportParser); + + // then + List assignedJsonReports = Whitebox.getInternalState(builder, "jsonFiles"); + Configuration assignedConfiguration = Whitebox.getInternalState(builder, "configuration"); + ReportParser assignedReportParser = Whitebox.getInternalState(builder, "reportParser"); + + assertThat(assignedJsonReports).isSameAs(jsonFiles); + assertThat(assignedConfiguration).isSameAs(configuration); + assertThat(assignedReportParser).isSameAs(builder.getReportParser()); + } + @Test void generateReports_GeneratesPages() { From 9113f5523d0d8a690a90adc1bd7eb93cb7818257 Mon Sep 17 00:00:00 2001 From: Jitendra_Singh2 Date: Fri, 15 Nov 2024 00:59:29 +0530 Subject: [PATCH 4/6] fix indentation in the signatures for the new constructor in ReportBuilder --- src/main/java/net/masterthought/cucumber/ReportBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/masterthought/cucumber/ReportBuilder.java b/src/main/java/net/masterthought/cucumber/ReportBuilder.java index 41300b323..752152cf2 100755 --- a/src/main/java/net/masterthought/cucumber/ReportBuilder.java +++ b/src/main/java/net/masterthought/cucumber/ReportBuilder.java @@ -70,7 +70,7 @@ public ReportBuilder(List jsonFiles, Configuration configuration) { reportParser = new ReportParser(configuration); } - public ReportBuilder(List jsonFiles, Configuration configuration, ReportParser reportParser){ + public ReportBuilder(List jsonFiles, Configuration configuration, ReportParser reportParser) { this.jsonFiles = jsonFiles; this.configuration = configuration; setReportParser(reportParser); From cd710c2630bd8e569bcb779798f7ff0e8148df7c Mon Sep 17 00:00:00 2001 From: Jitendra_Singh2 Date: Fri, 15 Nov 2024 10:02:42 +0530 Subject: [PATCH 5/6] remove the second constructor --- .../masterthought/cucumber/ReportBuilder.java | 6 ------ .../cucumber/ReportBuilderTest.java | 20 ------------------- 2 files changed, 26 deletions(-) diff --git a/src/main/java/net/masterthought/cucumber/ReportBuilder.java b/src/main/java/net/masterthought/cucumber/ReportBuilder.java index 752152cf2..ee616df5c 100755 --- a/src/main/java/net/masterthought/cucumber/ReportBuilder.java +++ b/src/main/java/net/masterthought/cucumber/ReportBuilder.java @@ -70,12 +70,6 @@ public ReportBuilder(List jsonFiles, Configuration configuration) { reportParser = new ReportParser(configuration); } - public ReportBuilder(List jsonFiles, Configuration configuration, ReportParser reportParser) { - this.jsonFiles = jsonFiles; - this.configuration = configuration; - setReportParser(reportParser); - } - public ReportParser getReportParser() { return reportParser; } diff --git a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java index d14f1f22f..535a81a48 100644 --- a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java +++ b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java @@ -62,26 +62,6 @@ void ReportBuilder_storesFilesAndConfiguration() { assertThat(assignedConfiguration).isSameAs(configuration); } - @Test - void ReportBuilder_usesCustomReportParser(){ - // given - final List jsonFiles = new ArrayList<>(); - final Configuration configuration = new Configuration(null, null); - final ReportParser reportParser = new ReportParser(configuration); - - // when - ReportBuilder builder = new ReportBuilder(jsonFiles, configuration, reportParser); - - // then - List assignedJsonReports = Whitebox.getInternalState(builder, "jsonFiles"); - Configuration assignedConfiguration = Whitebox.getInternalState(builder, "configuration"); - ReportParser assignedReportParser = Whitebox.getInternalState(builder, "reportParser"); - - assertThat(assignedJsonReports).isSameAs(jsonFiles); - assertThat(assignedConfiguration).isSameAs(configuration); - assertThat(assignedReportParser).isSameAs(reportParser); - } - @Test void ReportBuilder_setsAndGetsCustomReportParser(){ // given From 485f9ff335f63997015b32ec5d75f2e85cd5bf18 Mon Sep 17 00:00:00 2001 From: Jitendra_Singh2 Date: Sat, 16 Nov 2024 19:38:11 +0530 Subject: [PATCH 6/6] keep only relevant lines in the unit test --- .../java/net/masterthought/cucumber/ReportBuilderTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java index 535a81a48..e060d3595 100644 --- a/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java +++ b/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java @@ -74,12 +74,8 @@ void ReportBuilder_setsAndGetsCustomReportParser(){ builder.setReportParser(reportParser); // then - List assignedJsonReports = Whitebox.getInternalState(builder, "jsonFiles"); - Configuration assignedConfiguration = Whitebox.getInternalState(builder, "configuration"); ReportParser assignedReportParser = Whitebox.getInternalState(builder, "reportParser"); - assertThat(assignedJsonReports).isSameAs(jsonFiles); - assertThat(assignedConfiguration).isSameAs(configuration); assertThat(assignedReportParser).isSameAs(builder.getReportParser()); }