Commits

Jonathan Gilbert committed b8d3de8

added clinit test

Comments (0)

Files changed (2)

test/src/test/java/org/trillica/mangley/inject/InjectionTest.java

 import org.trillica.mangley.builder.StaticCall;
 import org.trillica.mangley.inject.target.Simple1;
 import org.trillica.mangley.inject.target.Simple2;
+import org.trillica.mangley.inject.target.StaticInit;
 
 import static org.hamcrest.CoreMatchers.not;
 import static org.junit.Assert.assertThat;
         assertThat(Stateful.getState(), not(0));
         System.out.println(Stateful.getState());
     }
+
+    @Test
+    public void validateStaticInit()
+    {
+        Mangler.applyConfig(ClassFilterConfig.byClass("org.trillica.mangley.inject.target.StaticInit", new JavaWrapper()
+        {
+            public ClassVisitor wrap(ClassVisitor cv)
+            {
+                return OperationBuilder.create(cv).injectCode(new StaticCall()
+                {
+                    public void call()
+                    {
+                        Stateful.setState(MangleContext.methodLocation());
+                    }
+                }).withLogging().build();
+            }
+        }));
+
+        Stateful.setState(0);
+        StaticInit.doNothing();
+        assertThat(Stateful.getState(), not(0));
+        System.out.println(Stateful.getState());
+    }
 }

test/src/test/java/org/trillica/mangley/inject/target/StaticInit.java

+package org.trillica.mangley.inject.target;
+
+public class StaticInit {
+    static {
+        System.out.println("static init");
+    }
+
+    public static void doNothing(){}
+
+
+}