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

Code clean-up #3027

Merged

Conversation

krmahadevan
Copy link
Member

  • Use finals as and when applicable
  • delete commented out code
  • convert inner classes into static

@@ -54,7 +54,7 @@ public void testCloneIfContainsTestsWithNamesMatchingAnyChildSuites(
dataProvider = "getData")
public void testCloneIfContainsTestsWithNamesMatchingAnyNegativeCondition(
XmlSuite xmlSuite, List<String> names) {
TestNamesMatcher testNamesHelper = new TestNamesMatcher(xmlSuite, names);
new TestNamesMatcher(xmlSuite, names);
Copy link
Member

Choose a reason for hiding this comment

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

Useless line

Copy link
Member Author

Choose a reason for hiding this comment

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

No it's not. The constructor of TestNamesMatcher internally does some edit checks and throws an exception and this test is vetting out that the exception is actually getting thrown or not.

Copy link
Member

Choose a reason for hiding this comment

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

But that is a side effect and breaks oop.
Could you considere to move the logic into a method used here and into the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didnt understand you here @juherr. The current implementation invokes a method named cloneIfContainsTestsWithNamesMatchingAny

This call is being done via constructor invocation. Are you suggesting that we move this call to some sort of a lazy invocation and leave the constructor to just member initialisation ? I believe that this rule is currently violated in multiple places within TestNG.

Copy link
Member

Choose a reason for hiding this comment

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

The object construction is useless here because we don't use any object.
The only reason to use it is because we know there are some side effects.
It will be more logical to call a real function instead.

It could be fixed every where possible

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be more logical to call a real function instead.

This wont be possible, because then it would change the semantics of what this class represents. We will have to alter all calls to explicitly call this new validation method. I believe that the validation is part of this class internals and the outside caller doesn't need to know anything about it.

Validating input parameters as part of Object instantiation, AFAIK is NOT a huge problem. It's a general practical to add semantic validations for input parameters passed into the constructor. This method cloneIfContainsTestsWithNamesMatchingAny is also doing such a semantic validation.

So can you please help me understand what is the real concern here so it can be addressed?

Copy link
Member Author

Choose a reason for hiding this comment

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

@juherr - Can you please let me know if this concern is addressed and if this PR can be proceeded further with approval and merge?

Copy link
Member

Choose a reason for hiding this comment

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

Calling a method sounds better but keep as it is for the moment

@@ -152,7 +153,8 @@ private void processMethod(

private static boolean excludeFactory(FactoryMethod fm, ITestContext ctx) {
return fm.getGroups().length != 0
&& ctx.getCurrentXmlTest().getExcludedGroups().containsAll(Arrays.asList(fm.getGroups()));
&& new HashSet<>(ctx.getCurrentXmlTest().getExcludedGroups())
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment that explain why hashset is used here.

@@ -54,7 +54,7 @@ public void testCloneIfContainsTestsWithNamesMatchingAnyChildSuites(
dataProvider = "getData")
public void testCloneIfContainsTestsWithNamesMatchingAnyNegativeCondition(
XmlSuite xmlSuite, List<String> names) {
TestNamesMatcher testNamesHelper = new TestNamesMatcher(xmlSuite, names);
new TestNamesMatcher(xmlSuite, names);
Copy link
Member

Choose a reason for hiding this comment

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

Calling a method sounds better but keep as it is for the moment

* Use finals as and when applicable
* delete commented out code
* convert inner classes into static
@krmahadevan krmahadevan merged commit e96e133 into testng-team:master Jan 5, 2024
8 of 9 checks passed
@krmahadevan krmahadevan deleted the additional_code_refactorings branch January 5, 2024 04:08
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.

None yet

2 participants