-
Notifications
You must be signed in to change notification settings - Fork 403
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
Change the visibility of the reportParser field #1216
Conversation
Hi @damianszczepanik, |
@@ -53,7 +53,7 @@ public class ReportBuilder { | |||
private static final ObjectMapper mapper = new ObjectMapper(); | |||
|
|||
private ReportResult reportResult; | |||
private final ReportParser reportParser; | |||
protected ReportParser reportParser; |
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 getter/setter method instead and add unit test into
cucumber-reporting/src/test/java/net/masterthought/cucumber/ReportBuilderTest.java
Line 28 in 5e084d9
class ReportBuilderTest extends ReportGenerator { |
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.
Thank you for your reply @damianszczepanik!
Let me try
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.
@damianszczepanik
I have made the required changes.
Please let me know if you have more suggestions.
@@ -71,6 +70,20 @@ public ReportBuilder(List<String> jsonFiles, Configuration configuration) { | |||
reportParser = new ReportParser(configuration); | |||
} | |||
|
|||
public ReportBuilder(List<String> jsonFiles, Configuration configuration, ReportParser reportParser) { |
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.
having getter and setter you don't need to add another constructor
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.
Indeed! it makes sense.
Let me remove the constructor.
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.
I have updated the description too.
builder.setReportParser(reportParser); | ||
|
||
// then | ||
List<String> assignedJsonReports = Whitebox.getInternalState(builder, "jsonFiles"); |
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.
no need to validate everything here - just assert what you are trying to validate -> leave only line 8 in this section
by this this is clear that this unit test validates only one particular method while others are validated by different tests
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.
sure Damian! I have updated this section
@@ -71,6 +70,14 @@ public ReportBuilder(List<String> jsonFiles, Configuration configuration) { | |||
reportParser = new ReportParser(configuration); | |||
} | |||
|
|||
public ReportParser getReportParser() { |
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.
right, this is what I expect o extend
// then | ||
ReportParser assignedReportParser = Whitebox.getInternalState(builder, "reportParser"); | ||
|
||
assertThat(assignedReportParser).isSameAs(builder.getReportParser()); |
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.
could be just
assertThat(reportParser).isSameAs(builder.getReportParser());
and no need to use Whitebox
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.
Duly noted Damian! Thank you.
Description
This pull request adds getter and setter methods for reportParser field with an overloaded constructor so that developers can extend the functionality of
ReportBuilder
with their own parsers, which provides greater flexibility for customized report processing.Changes
reportParser
fromprivate final
toprivate
,reportParser
.Motivation
In projects that require customized parsing behavior, developers may want to extend
ReportParser
with additional functionality. Adjusting the visibility ofreportParser
facilitates these extensions while maintaining the original functionality ofReportBuilder
.Testing
Verified that existing functionality remains unaffected after the changes.
Confirmed that a custom parser can now be added by sub classing
ReportParser
and utilized effectively.