aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest5.java
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2018-12-10 00:24:19 +0900
committerchibash <chiba@javassist.org>2018-12-10 00:24:19 +0900
commit52138ca4409ac336c4a4036af324a2a79b383d0c (patch)
treeac767038e16d0b680dd7a88166db7f4409200312 /src/test/javassist/JvstTest5.java
parent1a3d63712a3a5819dd54562983abbdd382f0d418 (diff)
downloadjavassist-52138ca4409ac336c4a4036af324a2a79b383d0c.tar.gz
javassist-52138ca4409ac336c4a4036af324a2a79b383d0c.zip
enables switch-case with string constants
Diffstat (limited to 'src/test/javassist/JvstTest5.java')
-rw-r--r--src/test/javassist/JvstTest5.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index c5eff4d1..1a9bd666 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -453,4 +453,35 @@ public class JvstTest5 extends JvstTestRoot {
cc.getClassFile().compact();
cc.toClass(test5.DefineClassCapability.class);
}
+
+ public void testSwitchCaseWithStringConstant() throws Exception {
+ CtClass cc = sloader.get("test5.SwitchCase");
+ cc.addMethod(CtNewMethod.make(
+ "public int run() {" +
+ " String s = \"foobar\";\n" +
+ " switch (s) {\n" +
+ " case STR1: return 1;\n" +
+ " case \"foobar\": return 2;\n" +
+ " default: return 3; }\n" +
+ "}\n", cc));
+ cc.writeFile();
+ Object obj = make(cc.getName());
+ assertEquals(2, invoke(obj, "run"));
+ }
+
+ public void testSwitchCaseWithStringConstant2() throws Exception {
+ CtClass cc = sloader.makeClass("test5.SwitchCase2");
+ cc.addMethod(CtNewMethod.make(
+ "public int run() {" +
+ " String s = \"foo\";\n" +
+ " switch (s) {\n" +
+ " case test5.SwitchCase.STR1: return 1;\n" +
+ " case \"foobar\": return 2;\n" +
+ " }\n" +
+ " return 3;\n" +
+ "}\n", cc));
+ cc.writeFile();
+ Object obj = make(cc.getName());
+ assertEquals(1, invoke(obj, "run"));
+ }
}