Skip to content

Commit

Permalink
Ensure no cache hit for method of different class, just if their simp…
Browse files Browse the repository at this point in the history
…le name and method name matches
  • Loading branch information
fhoeben committed Sep 15, 2016
1 parent 28fd1e3 commit 4cd2741
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/fitnesse/slim/fixtureInteraction/DefaultInteraction.java
Expand Up @@ -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);
}
}
}
24 changes: 23 additions & 1 deletion test/fitnesse/slim/fixtureInteraction/CachedInteractionTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 4cd2741

Please sign in to comment.