-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Minor refactoring around RunOrder enum #3106
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 0 additions & 123 deletions
123
testng-core-api/src/main/java/org/testng/internal/Systematiser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
testng-core/src/main/java/org/testng/internal/IOrderMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.testng.internal; | ||
|
||
import java.util.Comparator; | ||
import org.testng.ITestNGMethod; | ||
|
||
/** | ||
* Helps produce a {@link Comparator} that can be used to determine order of execution for a bunch | ||
* of {@link ITestNGMethod} methods. | ||
*/ | ||
@FunctionalInterface | ||
public interface IOrderMethods { | ||
|
||
/** @return - The {@link Comparator} to be used. */ | ||
Comparator<ITestNGMethod> comparator(); | ||
} |
85 changes: 85 additions & 0 deletions
85
testng-core/src/main/java/org/testng/internal/MethodSorting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.testng.internal; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.testng.ITestNGMethod; | ||
|
||
public enum MethodSorting implements Comparator<ITestNGMethod> { | ||
METHOD_NAMES("methods") { | ||
@Override | ||
public int compare(ITestNGMethod o1, ITestNGMethod o2) { | ||
String n1 = o1.getMethodName(); | ||
String n2 = o2.getMethodName(); | ||
return n1.compareTo(n2); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Method_Names"; | ||
} | ||
}, | ||
INSTANCES("instances") { | ||
@Override | ||
public int compare(ITestNGMethod o1, ITestNGMethod o2) { | ||
Comparator<ITestNGMethod> comparator = | ||
Comparator.comparingInt(ITestNGMethod::getPriority) | ||
.thenComparing(method -> method.getRealClass().getName()) | ||
.thenComparing(ITestNGMethod::getMethodName) | ||
.thenComparing(Object::toString) | ||
.thenComparing( | ||
method -> | ||
Optional.ofNullable(method.getFactoryMethodParamsInfo()) | ||
.map(it -> Arrays.toString(it.getParameters())) | ||
.orElse("")) | ||
.thenComparing(this::objectEquality); | ||
return comparator.compare(o1, o2); | ||
} | ||
|
||
private int objectEquality(ITestNGMethod a, ITestNGMethod b) { | ||
krmahadevan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Object one = IInstanceIdentity.getInstanceId(a.getInstance()); | ||
Object two = IInstanceIdentity.getInstanceId(b.getInstance()); | ||
if (IInstanceIdentity.isIdentityAware(one, two)) { | ||
return ((UUID) one).compareTo((UUID) two); | ||
} | ||
return Integer.compare(Objects.hashCode(one), Objects.hashCode(two)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Instance_Names"; | ||
} | ||
}, | ||
NONE("none") { | ||
@Override | ||
public int compare(ITestNGMethod o1, ITestNGMethod o2) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "No_Sorting"; | ||
} | ||
}; | ||
|
||
MethodSorting(String value) { | ||
this.value = value; | ||
} | ||
|
||
private final String value; | ||
|
||
public static Comparator<ITestNGMethod> basedOn() { | ||
String text = RuntimeBehavior.orderMethodsBasedOn(); | ||
return MethodSorting.parse(text); | ||
} | ||
|
||
private static MethodSorting parse(String input) { | ||
String text = Optional.ofNullable(input).orElse(""); | ||
return Arrays.stream(values()) | ||
.filter(it -> it.value.equalsIgnoreCase(text)) | ||
.findFirst() | ||
.orElse(INSTANCES); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider refactoring the
createSuiteRunner
method to improve readability and maintainability. Breaking it into smaller, more focused methods could enhance the code structure and make it easier to understand and modify in the future.