Skip to content

Commit 5c6ceda

Browse files
committed
Add test with two static blcks.
1 parent a241183 commit 5c6ceda

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/test/java/org/ikvm/javarefplugin/JavaRefPluginTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,47 @@ void staticFinalWithoutInitializerWithMultipleStaticBlocksAssignedOnce() throws
575575
assertFalse(getStaticBoolean(type, "FLAG"));
576576
}
577577

578+
@Test
579+
void stripsClassWithTwoStaticBlocks() throws Exception {
580+
Map<String, String> sources = new LinkedHashMap<>();
581+
sources.put(
582+
"example/TwoStaticBlocks.java",
583+
joinLines(
584+
"package example;",
585+
"",
586+
"public class TwoStaticBlocks {",
587+
" static final int REQUIRED;",
588+
" static int MUTABLE;",
589+
"",
590+
" static {",
591+
" MUTABLE = 123;",
592+
" }",
593+
"",
594+
" static {",
595+
" REQUIRED = 7;",
596+
" }",
597+
"}",
598+
""
599+
)
600+
);
601+
602+
CompilationResult result = compile(sources);
603+
Class<?> type = result.loadClass("example.TwoStaticBlocks");
604+
assertNotNull(type);
605+
assertEquals(0, getStaticInt(type, "REQUIRED"));
606+
assertEquals(0, getStaticInt(type, "MUTABLE"));
607+
}
608+
578609
private static boolean getStaticBoolean(Class<?> type, String fieldName) throws Exception {
579610
java.lang.reflect.Field field = type.getDeclaredField(fieldName);
580611
field.setAccessible(true);
581612
return field.getBoolean(null);
582613
}
583614

615+
private static int getStaticInt(Class<?> type, String fieldName) throws Exception {
616+
java.lang.reflect.Field field = type.getDeclaredField(fieldName);
617+
field.setAccessible(true);
618+
return field.getInt(null);
619+
}
620+
584621
}

0 commit comments

Comments
 (0)