Commit c29b9264 authored by Lubomir Bulej's avatar Lubomir Bulej

test: renamed afterinit to afterinit1, cleaned it up, and documented purpose

test: added afterinit2 to test to correct order of Before/After snippets in empty constructors 
parent 0ad0cf12
package ch.usi.dag.disl.test.suite.afterinit.app;
public class TargetClass {
public TargetClass() {
System.out.println("Constructing TargetClass");
}
static class TargetClass2 extends TargetClass {
public TargetClass2() {
System.out.println("Constructing TargetClass2");
System.out.println("Construction end");
}
public void method() {
}
}
public static void main(String[] args) {
TargetClass2 t = new TargetClass2();
t.method();
}
}
package ch.usi.dag.disl.test.suite.afterinit.instr;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
public class DiSLClass {
@Before(marker = AfterInitBodyMarker.class, scope = "*TargetClass2.<init>")
public static void after() {
System.out.println("Before");
}
@After(marker = AfterInitBodyMarker.class, scope = "*TargetClass2.<init>")
public static void afterThrowning() {
System.out.println("After");
}
}
Constructing TargetClass
Before
Constructing TargetClass2
Construction end
After
package ch.usi.dag.disl.test.suite.afterinit1.app;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
/**
* Tests that the {@link AfterInitBodyMarker} correctly marks method body
* starting after a call to the superclass constructor. The {@link Before}
* snippet should be placed before the constructor body, but after the call to
* the superclass constructor, while the {@link After} snippet should be placed
* after the constructor body.
*/
public class TargetClass {
public TargetClass () {
System.out.println ("TargetClass constructor begin");
System.out.println ("TargetClass constructor end");
}
static class TargetSubclass extends TargetClass {
public TargetSubclass () {
System.out.println ("TargetSubclass constructor begin");
System.out.println ("TargetSubclass constructor end");
}
public void method () {
System.out.println ("TargetSubclass method");
}
}
protected final String _thisClassName () {
return this.getClass ().getSimpleName ();
}
public static void main (final String [] args) {
final TargetSubclass t = new TargetSubclass ();
t.method ();
}
}
package ch.usi.dag.disl.test.suite.afterinit1.instr;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
public class DiSLClass {
@Before (marker = AfterInitBodyMarker.class, scope = "*.app.*Subclass*.<init>")
public static void after () {
System.out.println ("Before");
}
@After (marker = AfterInitBodyMarker.class, scope = "*.app.*Subclass*.<init>")
public static void afterThrowning () {
System.out.println ("After");
}
}
package ch.usi.dag.disl.test.suite.afterinit.junit;
package ch.usi.dag.disl.test.suite.afterinit1.junit;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
......@@ -7,6 +7,6 @@ import ch.usi.dag.disl.test.suite.DislOnlyTest;
@RunWith (JUnit4.class)
public class AfterInitTest extends DislOnlyTest {
public class AfterInit1Test extends DislOnlyTest {
}
TargetClass constructor begin
TargetClass constructor end
Before
TargetSubclass constructor begin
TargetSubclass constructor end
After
TargetSubclass method
package ch.usi.dag.disl.test.suite.afterinit2.app;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
/**
* Tests that the {@link Before} and {@link After} snippets are correctly
* ordered when instrumenting empty constructors using the
* {@link AfterInitBodyMarker}.
*/
public class TargetClass {
public TargetClass () {
// empty constructor
}
public static class TargetSubclass extends TargetClass {
public TargetSubclass () {
// empty constructor
}
}
public static void main (final String... args) {
final TargetClass t = new TargetSubclass ();
System.out.println (t.getClass ().getSimpleName ());
}
}
package ch.usi.dag.disl.test.suite.afterinit2.instr;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
@Before (marker = AfterInitBodyMarker.class, scope = "*.app.Target*.<init>")
public static void after (final MethodStaticContext msc) {
System.out.println (msc.thisClassSimpleName () +"."+ msc.thisMethodName () + " before");
}
@After (marker = AfterInitBodyMarker.class, scope = "*.app.Target*.<init>")
public static void afterThrowning (final MethodStaticContext msc) {
System.out.println (msc.thisClassSimpleName () +"."+ msc.thisMethodName () +" after");
}
}
package ch.usi.dag.disl.test.suite.afterinit2.junit;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import ch.usi.dag.disl.test.suite.DislOnlyTest;
@RunWith (JUnit4.class)
public class AfterInit2Test extends DislOnlyTest {
}
TargetClass.<init> before
TargetClass.<init> after
TargetClass$TargetSubclass.<init> before
TargetClass$TargetSubclass.<init> after
TargetSubclass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment