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

Reduce duplication #248

Merged
merged 5 commits into from Jun 20, 2020
Merged

Reduce duplication #248

merged 5 commits into from Jun 20, 2020

Conversation

beatngu13
Copy link
Member

@beatngu13 beatngu13 commented Apr 30, 2020

This is an early draft to fix #180.

In order to reduce the code duplication among SystemPropertyExtension and EnvironmentVariableExtension, I thought about an abstract base class for entry-based extensions, where entries (i.e. key-value pairs) shall be cleared or set.

As outlined above, this is a draft. There may be still some design flaws, the Javadoc is incomplete, no type wildcards … I just wanted to get some feedback if you think it is worth to further work on this, use a different approach or leave the extensions as they are. ✌️

Personally, I quite like it because when you look at SystemPropertyExtension and EnvironmentVariableExtension now, they are dead-simple.


I hereby agree to the terms of the JUnit Pioneer Contributor License Agreement.

@Bukama
Copy link
Member

Bukama commented May 1, 2020

Wow - nice duplicate code reduction so far! Like the approach and interested in how you go further

@sonarcloud
Copy link

sonarcloud bot commented May 2, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 5 Code Smells

96.2% 96.2% Coverage
0.0% 0.0% Duplication

@beatngu13
Copy link
Member Author

beatngu13 commented May 4, 2020

I think I'm done for the most part. I would keep AbstractEntryBasedExtension internal (package private), but in the future this may become public if users want to extend it for similar purposes.

Note that subclasses of AbstractEntryBasedExtension are currently responsible for discovering their own annotations. In a second step, we might move additional code into AbstractEntryBasedExtension. However, for now I think the way it is implemented is already a good improvement.

Proposed commit message:

Reduce duplication in envar and sysprop extensions

This PR reduces the duplication among `EnvironmentVariableExtension` and `SystemPropertyExtension` by introducing an abstract base class (`AbstractEntryBasedExtension`) for entry-based extensions, where entries (key-value pairs) can be cleared or set.

Closes: #180
PR: #248

@beatngu13 beatngu13 marked this pull request as ready for review May 4, 2020 17:50
@Bukama Bukama self-requested a review May 5, 2020 17:01
@Bukama
Copy link
Member

Bukama commented May 5, 2020

Will have a look, hope tomorrow

Copy link
Member

@Bukama Bukama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before - like it very much :)

@Bukama Bukama requested a review from aepfli May 9, 2020 07:10
@beatngu13
Copy link
Member Author

Open question: As with most traditional refactorings, I didn't touch existing tests. But do we want to have some additional tests for the new base class?

@Bukama
Copy link
Member

Bukama commented May 20, 2020

Open question: As with most traditional refactorings, I didn't touch existing tests. But do we want to have some additional tests for the new base class?

I vote for yes. And if there are existing tests of the old extension which, in core, test the same, because the functionality moved to the base class, than we should merge them into tests for the base class.

Copy link
Member

@aepfli aepfli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :) thank you

@Bukama
Copy link
Member

Bukama commented May 27, 2020

Open question: As with most traditional refactorings, I didn't touch existing tests. But do we want to have some additional tests for the new base class?

I asked @beatngu13 if he wants to add tests for the base class and we wants so. So we wait for an update :)

@nipafx
Copy link
Member

nipafx commented Jun 16, 2020

When I saw that we need six abstract methods, I was worried that the abstraction would the very fragile, bit it looks pretty good. Thank you very much @beatngu13! 👍 I was a bit surprised by the methods returning functional interfaces and turned that into "normal" methods (0c72122) - hope that's ok with you.

From my perspective, this can be merged.

@Bukama
Copy link
Member

Bukama commented Jun 18, 2020

From my perspective, this can be merged.

@beatngu13 wanted to add some additional tests. After that is done we can merge.

@nipafx
Copy link
Member

nipafx commented Jun 20, 2020

I looked at this for a few minutes, wondering what tests to add.

With abstract base classes, I usually try to come up with an abstract base class for the tests as well. The concrete classes can then be tested by concrete test classes that extend the base class. In that scenario, actual tests are usually only in the abstract test base class and concrete test classes only implement some factory methods. I don't think this will work here because I know of no way to handle the annotations (e.g. @SetEnvironmentVariable) - whether you try to put them into the abstract base class or the implementation, there are weird consequences.

I'm ok with just testing the implementation, i.e. just EnvironmentVariableExtension and SystemPropertyExtension without any tests for the abstract base class.

If you still want to add tests, keep in mind that we don't want to "overtest", i.e. if there's a bug in the abstract base class, we don't need its tests and the implementations to fail if that just adds more failing tests without providing more insight.

@beatngu13
Copy link
Member Author

@nicolaiparlog makes sense, I'm fine with that. 👍

Just did a rebase to current master, so feel free to merge.

@sonarcloud
Copy link

sonarcloud bot commented Jun 20, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 1 Security Hotspot to review)
Code Smell A 0 Code Smells

96.2% 96.2% Coverage
0.0% 0.0% Duplication

@nipafx nipafx merged commit b868d16 into junit-pioneer:master Jun 20, 2020
@beatngu13 beatngu13 deleted the issue/180-reduce-duplication branch June 20, 2020 13:16
@beatngu13 beatngu13 mentioned this pull request Jan 9, 2023
14 tasks
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.

Reduce duplication
4 participants