aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2016-09-18 02:32:31 +0900
committerchibash <chiba@javassist.org>2016-09-18 02:32:31 +0900
commitf6992d66a0d786d8872f5e0754d3270a4728e10c (patch)
tree2c627900aa60161bf2682a2ecabe173688ce34e3 /src/test
parentc0b62eeabad1f96da80f26339f6cd1986330174f (diff)
downloadjavassist-f6992d66a0d786d8872f5e0754d3270a4728e10c.tar.gz
javassist-f6992d66a0d786d8872f5e0754d3270a4728e10c.zip
allows adding a default method to an interface type.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/javassist/JvstTest3.java3
-rw-r--r--src/test/javassist/JvstTest5.java16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/test/javassist/JvstTest3.java b/src/test/javassist/JvstTest3.java
index d99fde1f..427479d1 100644
--- a/src/test/javassist/JvstTest3.java
+++ b/src/test/javassist/JvstTest3.java
@@ -1086,7 +1086,8 @@ public class JvstTest3 extends JvstTestRoot {
CtMethod m3 = CtMethod.make("public void foo3() {}", cc);
try {
cc.addMethod(m3);
- fail();
+ if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_8)
+ fail();
}
catch (CannotCompileException e) {
// System.out.println(e);
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 792fed6e..779df525 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -235,4 +235,20 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(ctClass.getName());
assertEquals(1, invoke(obj, "run"));
}
+
+ public void testAddDefaultMethod() throws Exception {
+ CtClass cc = sloader.makeInterface("test5.AddDefaultMethod");
+ cc.addMethod(CtNewMethod.make("static int foo() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("public static int foo1() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("public int foo2() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("int foo3() { return 1; }", cc));
+ try {
+ cc.addMethod(CtNewMethod.make("private int foo4() { return 1; }", cc));
+ fail();
+ } catch (CannotCompileException e) {}
+ try {
+ cc.addMethod(CtNewMethod.make("private static int foo5() { return 1; }", cc));
+ fail();
+ } catch (CannotCompileException e) {}
+ }
}