Skip to content

Commit

Permalink
Merge pull request #113 from jglick/interfaceMethods
Browse files Browse the repository at this point in the history
Verifying that web methods may be defined as default interface methods
  • Loading branch information
jglick authored Aug 3, 2017
2 parents 5f5e5fa + 6f9acc1 commit 8baac29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion core/src/test/java/org/kohsuke/stapler/DispatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,38 @@ public void testPutInheritance() throws Exception {
assertEquals("POST: Hello", p.getContent());
}


public void testInterfaceMethods() throws Exception {
WebClient wc = new WebClient();
try {
wc.getPage(new URL(url, "usesInterfaceMethods/foo"));
fail();
} catch (FailingHttpStatusCodeException x) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, x.getStatusCode());
}
assertEquals("default", wc.getPage(new WebRequestSettings(new URL(url, "usesInterfaceMethods/foo"), HttpMethod.POST)).getWebResponse().getContentAsString().trim());
try {
wc.getPage(new URL(url, "overridesInterfaceMethods/foo"));
fail();
} catch (FailingHttpStatusCodeException x) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, x.getStatusCode());
}
assertEquals("due to UnionAnnotatedElement it is even inherited", "overridden", wc.getPage(new WebRequestSettings(new URL(url, "overridesInterfaceMethods/foo"), HttpMethod.POST)).getWebResponse().getContentAsString().trim());
}
public interface InterfaceWithWebMethods {
@RequirePOST
default HttpResponse doFoo() {
return HttpResponses.plainText("default");
}
}
public class UsesInterfaceMethods implements InterfaceWithWebMethods {}
public class OverridesInterfaceMethods implements InterfaceWithWebMethods {
@Override
public HttpResponse doFoo() {
return HttpResponses.plainText("overridden");
}
}
public final UsesInterfaceMethods usesInterfaceMethods = new UsesInterfaceMethods();
public final OverridesInterfaceMethods overridesInterfaceMethods = new OverridesInterfaceMethods();

//===================================================================

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.level>7</java.level>
<java.level>8</java.level>
</properties>

<build>
Expand Down

0 comments on commit 8baac29

Please sign in to comment.