@Test
  public void testMethodId() throws SecurityException, NoSuchMethodException {
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    Iterator<AnnotatedMethod<? super Chair>> it = chair3.getMethods().iterator();
    AnnotatedMethod<? super Chair> method = it.next();
    while (!method.getJavaMember().getName().equals("sit")) method = it.next();
    String id = AnnotatedTypes.createCallableId(method);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.sit[@javax.enterprise.inject.Produces()]()",
        id,
        "wrong id for method :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    chair3 = builder.create();
    it = chair3.getMethods().iterator();
    method = it.next();
    while (!method.getJavaMember().getName().equals("sit")) method = it.next();
    id = AnnotatedTypes.createCallableId(method);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.sit()", id, "wrong id for method :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToMethod(Chair.class.getMethod("sit"), new ComfyChairLiteral());
    chair3 = builder.create();
    it = chair3.getMethods().iterator();
    method = it.next();
    while (!method.getJavaMember().getName().equals("sit")) method = it.next();
    id = AnnotatedTypes.createCallableId(method);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.sit[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]()",
        id,
        "wrong id for method :" + id);
  }
Example #2
0
 public static String forProducerMethod(
     EnhancedAnnotatedMethod<?, ?> method, AbstractClassBean<?> declaringBean) {
   if (declaringBean.getEnhancedAnnotated().isDiscovered()) {
     return forProducerMethod(
         declaringBean.getAnnotated().getIdentifier(),
         DeclaredMemberIndexer.getIndexForMethod(method.getJavaMember()));
   }
   return getPrefix(ProducerMethod.class)
       .append(method.getDeclaringType().slim().getIdentifier())
       .append(AnnotatedTypes.createCallableId(method))
       .toString();
 }