Skip to content
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

Merged
merged 8 commits into from
Nov 16, 2024

Conversation

jit3pam
Copy link
Contributor

@jit3pam jit3pam commented Nov 10, 2024

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

  1. Changed reportParser from private final to private,
  2. Add getter and setter methods for reportParser.
  3. Added unit test

Motivation

In projects that require customized parsing behavior, developers may want to extend ReportParser with additional functionality. Adjusting the visibility of reportParser facilitates these extensions while maintaining the original functionality of ReportBuilder.

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.

@jit3pam jit3pam marked this pull request as ready for review November 10, 2024 18:23
@jit3pam
Copy link
Contributor Author

jit3pam commented Nov 12, 2024

Hi @damianszczepanik,
I have created this pull request to contribute towards the project. The GitHub checks are successful and are passing.
Please let me know if there is any aspect missing in the request.

@@ -53,7 +53,7 @@ public class ReportBuilder {
private static final ObjectMapper mapper = new ObjectMapper();

private ReportResult reportResult;
private final ReportParser reportParser;
protected ReportParser reportParser;
Copy link
Owner

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

class ReportBuilderTest extends ReportGenerator {

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@jit3pam jit3pam marked this pull request as draft November 14, 2024 16:55
@jit3pam jit3pam marked this pull request as ready for review November 14, 2024 19:40
@@ -71,6 +70,20 @@ public ReportBuilder(List<String> jsonFiles, Configuration configuration) {
reportParser = new ReportParser(configuration);
}

public ReportBuilder(List<String> jsonFiles, Configuration configuration, ReportParser reportParser) {
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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");
Copy link
Owner

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

Copy link
Contributor Author

@jit3pam jit3pam Nov 16, 2024

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() {
Copy link
Owner

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());
Copy link
Owner

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

Copy link
Contributor Author

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.

@damianszczepanik damianszczepanik merged commit 24505dd into damianszczepanik:master Nov 16, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants