Skip to content

Commit

Permalink
Use 'toString' instead of 'hashCode' for Method (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbabcoc authored May 5, 2022
1 parent 9bcc057 commit aa64192
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/nordstrom/automation/junit/CreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DepthGauge apply(Integer input) {
public static Object intercept(@This final Object runner, @Argument(0) final FrameworkMethod method,
@SuperCall final Callable<?> proxy) throws Exception {

Integer hashCode = Objects.hash(runner, method);
Integer hashCode = Objects.hash(runner, method.toString());
DepthGauge depthGauge = LifecycleHooks.computeIfAbsent(METHOD_DEPTH.get(), hashCode, NEW_INSTANCE);
depthGauge.increaseDepth();

Expand Down Expand Up @@ -99,7 +99,7 @@ public static Object intercept(@This final Object runner, @Argument(0) final Fra
* @return target test class instance
*/
static Object getTargetFor(Object runner, FrameworkMethod method) {
return HASHCODE_TO_TARGET.remove(Objects.hash(runner, method));
return HASHCODE_TO_TARGET.remove(Objects.hash(runner, method.toString()));
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ static Object getRunnerFor(Object target) {
* @param target test class instance
*/
static void releaseMappingsFor(Object runner, FrameworkMethod method, Object target) {
HASHCODE_TO_TARGET.remove(Objects.hash(runner, method));
HASHCODE_TO_TARGET.remove(Objects.hash(runner, method.toString()));
if (target != null) {
TARGET_TO_METHOD.remove(toMapKey(target));
TARGET_TO_RUNNER.remove(toMapKey(target));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void interceptor(@Argument(0) final RunNotifier notifier,
// otherwise (target not yet created)
} else {
// store [runner + method] => description mapping for 'setTestTarget' method
HASHCODE_TO_DESCRIPTION.put(Objects.hash(runner, method), description.hashCode());
HASHCODE_TO_DESCRIPTION.put(Objects.hash(runner, method.toString()), description.hashCode());
}
} else {
throw new IllegalStateException("unable to determine method");
Expand Down Expand Up @@ -181,7 +181,7 @@ static void createMappingsFor(Integer descriptionHash, Object target) {
static void releaseMappingsFor(EachTestNotifier notifier) {
Description description = getDescriptionOf(notifier);
AtomicTest atomicTest = releaseAtomicTestOf(description);
HASHCODE_TO_DESCRIPTION.remove(Objects.hash(atomicTest.getRunner(), atomicTest.getIdentity()));
HASHCODE_TO_DESCRIPTION.remove(Objects.hash(atomicTest.getRunner(), atomicTest.getIdentity().toString()));
Object target = DESCRIPTION_TO_TARGET.remove(description.hashCode());
if (target != null) {
TARGET_TO_DESCRIPTION.remove(toMapKey(target));
Expand Down Expand Up @@ -242,6 +242,6 @@ private static Description getDescriptionOf(EachTestNotifier notifier) {
* @return {@link Description} hash code
*/
private static Integer getDescriptionHashFor(Object runner, FrameworkMethod method) {
return HASHCODE_TO_DESCRIPTION.get(Objects.hash(runner, method));
return HASHCODE_TO_DESCRIPTION.get(Objects.hash(runner, method.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class GetAnnotations {

private static final Map<Integer, Annotation[]> ANNOTATIONS = new ConcurrentHashMap<>();
private static final Map<String, Annotation[]> ANNOTATIONS = new ConcurrentHashMap<>();

/**
* Interceptor for the {@link org.junit.runners.model.FrameworkMethod#getAnnotations} method.
Expand All @@ -36,10 +36,10 @@ public static Annotation[] intercept(@This final FrameworkMethod method) throws
* @return array of annotations for the specified method
*/
static Annotation[] getAnnotationsFor(FrameworkMethod method) {
Annotation[] annotations = ANNOTATIONS.get(method.hashCode());
Annotation[] annotations = ANNOTATIONS.get(method.toString());
if (annotations == null) {
annotations = method.getMethod().getAnnotations();
ANNOTATIONS.put(method.hashCode(), annotations);
ANNOTATIONS.put(method.toString(), annotations);
}
return annotations;
}
Expand All @@ -50,7 +50,7 @@ static Annotation[] getAnnotationsFor(FrameworkMethod method) {
* @param method target {@link FrameworkMethod} object
*/
static void releaseAnnotationsFor(FrameworkMethod method) {
ANNOTATIONS.remove(method.hashCode());
ANNOTATIONS.remove(method.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void testFinished(Description description) throws IllegalArgumentExceptio
Object runner = atomicTest.getRunner();
FrameworkMethod method = atomicTest.getIdentity();
String name = method.getName() + "(" + LifecycleHooks.toMapKey(runner) + ")";
hashCodeMap.put(Objects.hash(runner, method), name);
hashCodeMap.put(Objects.hash(runner, method.toString()), name);

Object target = LifecycleHooks.getTargetOf(description);
if (target != null) {
Expand Down

0 comments on commit aa64192

Please sign in to comment.