Skip to content

Commit

Permalink
补充217问题解法
Browse files Browse the repository at this point in the history
  • Loading branch information
dongchenxu committed Dec 8, 2019
1 parent 869c623 commit 03a9fbf
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
import org.junit.Test;

import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static com.alibaba.jvm.sandbox.api.listener.ext.EventWatchBuilder.PatternType.REGEX;
import static com.alibaba.jvm.sandbox.core.util.matcher.structure.ClassStructureFactory.createClassStructure;
import static com.alibaba.jvm.sandbox.qatest.core.util.QaClassUtils.toByteArray;

Expand Down Expand Up @@ -100,4 +105,55 @@ public void onEvent(Event event) throws Throwable {

}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface TestAAnnotation {

}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface TestBAnnotation {

}

@TestAAnnotation
@TestBAnnotation
class TestAB {

}

@TestAAnnotation
class TestA {

}

@TestBAnnotation
class TestB {

}

@Test
public void matching__TestA_or_TestB__Annotation() {

final GetMatcherModuleEventWatcher watcher = new GetMatcherModuleEventWatcher();

new EventWatchBuilder(watcher, REGEX)
.onAnyClass()
.hasAnnotationTypes(".*Test(A|B)Annotation")
.onAnyBehavior()
.onWatch(new EventListener() {
@Override
public void onEvent(Event event) throws Throwable {

}
});

final Matcher matcher = watcher.getMatcher();
Assert.assertTrue(matcher.matching(createClassStructure(TestA.class)).isMatched());
Assert.assertTrue(matcher.matching(createClassStructure(TestB.class)).isMatched());
Assert.assertTrue(matcher.matching(createClassStructure(TestAB.class)).isMatched());

}

}

0 comments on commit 03a9fbf

Please sign in to comment.