-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring around RunOrder enum
Renamed and re-organised some internal classes The run order based on instances was using Hash codes to determine execution order. Now that we have Unique identity aware test class object containers, we should be first trying to use that and if it’s not available only then fall Back to using object hash codes (This is for instance aware comparators)
- Loading branch information
1 parent
e5218ab
commit 2e5d8bf
Showing
9 changed files
with
121 additions
and
134 deletions.
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) { | ||
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