Skip to content

Commit aa64192

Browse files
authored
Use 'toString' instead of 'hashCode' for Method (#123)
1 parent 9bcc057 commit aa64192

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/main/java/com/nordstrom/automation/junit/CreateTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public DepthGauge apply(Integer input) {
6060
public static Object intercept(@This final Object runner, @Argument(0) final FrameworkMethod method,
6161
@SuperCall final Callable<?> proxy) throws Exception {
6262

63-
Integer hashCode = Objects.hash(runner, method);
63+
Integer hashCode = Objects.hash(runner, method.toString());
6464
DepthGauge depthGauge = LifecycleHooks.computeIfAbsent(METHOD_DEPTH.get(), hashCode, NEW_INSTANCE);
6565
depthGauge.increaseDepth();
6666

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

105105
/**
@@ -130,7 +130,7 @@ static Object getRunnerFor(Object target) {
130130
* @param target test class instance
131131
*/
132132
static void releaseMappingsFor(Object runner, FrameworkMethod method, Object target) {
133-
HASHCODE_TO_TARGET.remove(Objects.hash(runner, method));
133+
HASHCODE_TO_TARGET.remove(Objects.hash(runner, method.toString()));
134134
if (target != null) {
135135
TARGET_TO_METHOD.remove(toMapKey(target));
136136
TARGET_TO_RUNNER.remove(toMapKey(target));

src/main/java/com/nordstrom/automation/junit/EachTestNotifierInit.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static void interceptor(@Argument(0) final RunNotifier notifier,
8484
// otherwise (target not yet created)
8585
} else {
8686
// store [runner + method] => description mapping for 'setTestTarget' method
87-
HASHCODE_TO_DESCRIPTION.put(Objects.hash(runner, method), description.hashCode());
87+
HASHCODE_TO_DESCRIPTION.put(Objects.hash(runner, method.toString()), description.hashCode());
8888
}
8989
} else {
9090
throw new IllegalStateException("unable to determine method");
@@ -181,7 +181,7 @@ static void createMappingsFor(Integer descriptionHash, Object target) {
181181
static void releaseMappingsFor(EachTestNotifier notifier) {
182182
Description description = getDescriptionOf(notifier);
183183
AtomicTest atomicTest = releaseAtomicTestOf(description);
184-
HASHCODE_TO_DESCRIPTION.remove(Objects.hash(atomicTest.getRunner(), atomicTest.getIdentity()));
184+
HASHCODE_TO_DESCRIPTION.remove(Objects.hash(atomicTest.getRunner(), atomicTest.getIdentity().toString()));
185185
Object target = DESCRIPTION_TO_TARGET.remove(description.hashCode());
186186
if (target != null) {
187187
TARGET_TO_DESCRIPTION.remove(toMapKey(target));
@@ -242,6 +242,6 @@ private static Description getDescriptionOf(EachTestNotifier notifier) {
242242
* @return {@link Description} hash code
243243
*/
244244
private static Integer getDescriptionHashFor(Object runner, FrameworkMethod method) {
245-
return HASHCODE_TO_DESCRIPTION.get(Objects.hash(runner, method));
245+
return HASHCODE_TO_DESCRIPTION.get(Objects.hash(runner, method.toString()));
246246
}
247247
}

src/main/java/com/nordstrom/automation/junit/GetAnnotations.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public class GetAnnotations {
1515

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

1818
/**
1919
* Interceptor for the {@link org.junit.runners.model.FrameworkMethod#getAnnotations} method.
@@ -36,10 +36,10 @@ public static Annotation[] intercept(@This final FrameworkMethod method) throws
3636
* @return array of annotations for the specified method
3737
*/
3838
static Annotation[] getAnnotationsFor(FrameworkMethod method) {
39-
Annotation[] annotations = ANNOTATIONS.get(method.hashCode());
39+
Annotation[] annotations = ANNOTATIONS.get(method.toString());
4040
if (annotations == null) {
4141
annotations = method.getMethod().getAnnotations();
42-
ANNOTATIONS.put(method.hashCode(), annotations);
42+
ANNOTATIONS.put(method.toString(), annotations);
4343
}
4444
return annotations;
4545
}
@@ -50,7 +50,7 @@ static Annotation[] getAnnotationsFor(FrameworkMethod method) {
5050
* @param method target {@link FrameworkMethod} object
5151
*/
5252
static void releaseAnnotationsFor(FrameworkMethod method) {
53-
ANNOTATIONS.remove(method.hashCode());
53+
ANNOTATIONS.remove(method.toString());
5454
}
5555

5656
}

src/test/java/com/nordstrom/automation/junit/ReferenceChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void testFinished(Description description) throws IllegalArgumentExceptio
220220
Object runner = atomicTest.getRunner();
221221
FrameworkMethod method = atomicTest.getIdentity();
222222
String name = method.getName() + "(" + LifecycleHooks.toMapKey(runner) + ")";
223-
hashCodeMap.put(Objects.hash(runner, method), name);
223+
hashCodeMap.put(Objects.hash(runner, method.toString()), name);
224224

225225
Object target = LifecycleHooks.getTargetOf(description);
226226
if (target != null) {

0 commit comments

Comments
 (0)