Exemplo n.º 1
0
  @Test
  public void hasEnclodingMethod() throws Exception {
    JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
    String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass";
    InstrumentClass testObject = pool.getClass(null, testObjectName, null);
    Assert.assertEquals(testObject.getName(), testObjectName);

    assertEquals(
        1,
        testObject
            .getNestedClasses(
                ClassFilters.enclosingMethod("enclosingMethod", "java.lang.String", "int"))
            .size());
    assertEquals(
        0,
        testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "int")).size());
  }
Exemplo n.º 2
0
  @Test
  public void getNestedClasses() throws Exception {
    JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
    String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass";
    InstrumentClass testObject = pool.getClass(null, testObjectName, null);
    Assert.assertEquals(testObject.getName(), testObjectName);

    // find class name condition.
    final String targetClassName =
        "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass$InstanceInner";
    for (InstrumentClass c : testObject.getNestedClasses(ClassFilters.name(targetClassName))) {
      assertEquals(targetClassName, c.getName());
    }

    // find enclosing method condition.
    assertEquals(
        2,
        testObject.getNestedClasses(ClassFilters.enclosingMethod("annonymousInnerClass")).size());

    // find interface condition.
    assertEquals(
        2,
        testObject
            .getNestedClasses(ClassFilters.interfaze("java.util.concurrent.Callable"))
            .size());

    // find enclosing method & interface condition.
    assertEquals(
        1,
        testObject
            .getNestedClasses(
                ClassFilters.chain(
                    ClassFilters.enclosingMethod("annonymousInnerClass"),
                    ClassFilters.interfaze("java.util.concurrent.Callable")))
            .size());
  }