Skip to content

Commit

Permalink
Merge pull request #476 from nykolaslima/generic-controller-linkTo
Browse files Browse the repository at this point in the history
Fixing linkTo for GenericController with args. Fixes #464
  • Loading branch information
lucascs committed Nov 7, 2012
2 parents b5ad875 + ecd55f5 commit cba5a00
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Expand Up @@ -80,7 +80,7 @@ public Linker get(Object key) {
} }
private Method findMethodWithName(Class<?> type, String name) { private Method findMethodWithName(Class<?> type, String name) {
for (Method method : type.getDeclaredMethods()) { for (Method method : type.getDeclaredMethods()) {
if (method.getName().equals(name)) { if (!method.isBridge() && method.getName().equals(name)) {
return method; return method;
} }
} }
Expand Down
@@ -0,0 +1,12 @@
package br.com.caelum.vraptor.view;

/**
* Controller used to test Generic Controllers on LinkToHandler
* @author Nykolas Lima
*
*/
public class GenericController<T> {
public void method(T entity) {
System.out.println("Do Something");
}
}
Expand Up @@ -54,6 +54,15 @@ public void shouldReturnWantedUrlWithParamArgs() {
String uri = handler.get(TestController.class).get("method").get(a).get(b).toString(); String uri = handler.get(TestController.class).get("method").get(a).get(b).toString();
assertThat(uri, is("/path/expectedURL")); assertThat(uri, is("/path/expectedURL"));
} }

@Test
public void shouldReturnWantedUrlForOverrideMethodWithParamArgs() throws NoSuchMethodException, SecurityException {
String a = "test";
when(router.urlFor(SubGenericController.class, SubGenericController.class.getDeclaredMethod("method", new Class[]{String.class}), new Object[]{a})).thenReturn("/expectedURL");
//${linkTo[TestSubGenericController].method['test']}]
String uri = handler.get(SubGenericController.class).get("method").get(a).toString();
assertThat(uri, is("/path/expectedURL"));
}


static class TestController { static class TestController {
void method(String a, int b) { void method(String a, int b) {
Expand Down
@@ -0,0 +1,16 @@
package br.com.caelum.vraptor.view;

/**
* Controller used to test Generic Controllers on LinkToHandler
* @author Nykolas Lima
*
*/
public class SubGenericController extends GenericController<String> {
public void method(String string) {
System.out.println("Do another thing by Sub Generic Controller");
}

public void okMethod(String string) {
System.out.println("OKOK");
}
}

0 comments on commit cba5a00

Please sign in to comment.