From 4cd274113d338193b27f1c65d425a096fa464490 Mon Sep 17 00:00:00 2001 From: Fried Hoeben Date: Thu, 15 Sep 2016 10:59:25 +0200 Subject: [PATCH] Ensure no cache hit for method of different class, just if their simple name and method name matches --- .../fixtureInteraction/CachedInteraction.java | 2 +- .../DefaultInteraction.java | 5 +++- .../CachedInteractionTest.java | 24 ++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/fitnesse/slim/fixtureInteraction/CachedInteraction.java b/src/fitnesse/slim/fixtureInteraction/CachedInteraction.java index ace6475282..2fa273ff63 100644 --- a/src/fitnesse/slim/fixtureInteraction/CachedInteraction.java +++ b/src/fitnesse/slim/fixtureInteraction/CachedInteraction.java @@ -83,7 +83,7 @@ private static final class MethodKey { private final int nArgs; public MethodKey(Class k, String method, int nArgs) { - this.k = k.getSimpleName(); + this.k = k.getName(); this.method = method; this.nArgs = nArgs; } diff --git a/src/fitnesse/slim/fixtureInteraction/DefaultInteraction.java b/src/fitnesse/slim/fixtureInteraction/DefaultInteraction.java index 499c468220..b167cd35eb 100755 --- a/src/fitnesse/slim/fixtureInteraction/DefaultInteraction.java +++ b/src/fitnesse/slim/fixtureInteraction/DefaultInteraction.java @@ -151,6 +151,9 @@ public Object methodInvoke(Method method, Object instance, Object... convertedAr } else { throw e.getTargetException(); } - } + } catch (IllegalArgumentException e) { + throw new RuntimeException("Bad call of: " + method.getDeclaringClass().getName() + "." + method.getName() + + ". On instance of: " + instance.getClass().getName(), e); + } } } diff --git a/test/fitnesse/slim/fixtureInteraction/CachedInteractionTest.java b/test/fitnesse/slim/fixtureInteraction/CachedInteractionTest.java index 4d1a1dff13..5afe5dd6d5 100644 --- a/test/fitnesse/slim/fixtureInteraction/CachedInteractionTest.java +++ b/test/fitnesse/slim/fixtureInteraction/CachedInteractionTest.java @@ -2,10 +2,11 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.Collections; +import fitnesse.slim.test.TableTableIncFirstCol; import fitnesse.testsystems.slim.SlimTestContext; import fitnesse.testsystems.slim.Table; -import fitnesse.testsystems.slim.tables.ScriptTable; import fitnesse.testsystems.slim.tables.SlimTable; import org.junit.Test; import org.junit.runner.RunWith; @@ -130,6 +131,27 @@ public void canFindMethodWithArguments() { verify(interaction, times(1)).handleMethodCacheMiss(findMethod, instance, new Object[3]); } + @Test + public void canFindMethodWithSameSimpleClassName() { + String findMethod = "doTable"; + TableTableIncFirstCol instance = new TableTableIncFirstCol(); + fitnesse.slim.test.statementexecutorconsumer.TableTableIncFirstCol consInstance = + new fitnesse.slim.test.statementexecutorconsumer.TableTableIncFirstCol(); + + Method method = interaction.findMatchingMethod(findMethod, instance, Collections.emptyList()); + + assertEquals(findMethod, method.getName()); + assertEquals("Method returned is defined by the wrong class (i.e. not the class of the instance passed)", + instance.getClass(), method.getDeclaringClass()); + + //2nd call + Method consMethod = interaction.findMatchingMethod(findMethod, consInstance, Collections.emptyList()); + + assertEquals(findMethod, consMethod.getName()); + assertEquals("Method returned is defined by the wrong class (i.e. not the class of the instance passed)", + consInstance.getClass(), consMethod.getDeclaringClass()); + } + @Test public void canDealWithNoMethod() { String findMethod = "addChildTable";