-
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.
Add Unique Id for all test class instances
Closes #3079
- Loading branch information
1 parent
eb80671
commit c3d6058
Showing
27 changed files
with
455 additions
and
98 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.testng; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
/** Represents the associations of a class with one or more instances. */ | ||
public interface IObject { | ||
|
||
default IdentifiableObject[] getObjects(boolean create) { | ||
return getObjects(create, ""); | ||
} | ||
|
||
IdentifiableObject[] getObjects(boolean create, String errorMsgPrefix); | ||
|
||
long[] getInstanceHashCodes(); | ||
|
||
void addObject(IdentifiableObject instance); | ||
|
||
/** A wrapper object that associates a unique id to every unique test class object. */ | ||
class IdentifiableObject { | ||
private final Object instance; | ||
private final UUID instanceId; | ||
|
||
public IdentifiableObject(Object instance) { | ||
this(instance, UUID.randomUUID()); | ||
} | ||
|
||
public IdentifiableObject(Object instance, UUID instanceId) { | ||
this.instance = instance; | ||
this.instanceId = instanceId; | ||
} | ||
|
||
public static Object unwrap(IdentifiableObject object) { | ||
if (object == null) { | ||
return null; | ||
} | ||
return object.getInstance(); | ||
} | ||
|
||
public UUID getInstanceId() { | ||
return instanceId; | ||
} | ||
|
||
public Object getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
IdentifiableObject that = (IdentifiableObject) object; | ||
return Objects.equals(instance, that.instance); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(instance); | ||
} | ||
} | ||
} |
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
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.