Skip to content

Commit

Permalink
Adapt no-arg value from interface-based InvocationHandler callback
Browse files Browse the repository at this point in the history
Closes gh-30756
  • Loading branch information
jhoeller committed Jun 26, 2023
1 parent 599ac58 commit b77d4d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Expand Up @@ -745,8 +745,8 @@ public Object intercept(@Nullable Object obj, Method method, Object[] args, @Nul

@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return intercept(proxy, method, args, null);
public Object invoke(Object proxy, Method method, @Nullable Object[] args) {
return intercept(proxy, method, (args != null ? args : new Object[0]), null);
}

@Override
Expand Down
Expand Up @@ -293,6 +293,14 @@ public void fromMethodNameWithMetaAnnotation() {
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/input");
}

@Test
public void fromMethodCallOnSubclass() {
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();

assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
}

@Test
public void fromMethodCallPlain() {
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
Expand All @@ -302,11 +310,27 @@ public void fromMethodCallPlain() {
}

@Test
public void fromMethodCallOnSubclass() {
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
public void fromMethodCallPlainWithNoArguments() {
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod()).build();

assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
}

@Test
public void fromMethodCallPlainOnInterface() {
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod(null)).build();

assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/else");
}

@Test
public void fromMethodCallPlainWithNoArgumentsOnInterface() {
UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod()).build();

assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/noarg");
}

@Test
Expand Down Expand Up @@ -575,6 +599,11 @@ HttpEntity<Void> myMethod(@RequestBody Object payload) {
return null;
}

@RequestMapping("/noarg")
HttpEntity<Void> myMethod() {
return null;
}

@RequestMapping("/{id}/foo")
HttpEntity<Void> methodWithPathVariable(@PathVariable String id) {
return null;
Expand Down Expand Up @@ -616,6 +645,17 @@ static class ExtendedController extends ControllerWithMethods {
}


@RequestMapping("/something")
public interface ControllerInterface {

@RequestMapping("/else")
HttpEntity<Void> myMethod(@RequestBody Object payload);

@RequestMapping("/noarg")
HttpEntity<Void> myMethod();
}


@RequestMapping("/user/{userId}/contacts")
static class UserContactController {

Expand Down

0 comments on commit b77d4d0

Please sign in to comment.