示例#1
0
  @Test
  public void testFieldId() throws SecurityException, NoSuchFieldException {
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    AnnotatedField<? super Chair> field = chair3.getFields().iterator().next();
    String id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs[@javax.enterprise.inject.Produces()]",
        id,
        "wrong id for field :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    chair3 = builder.create();
    field = chair3.getFields().iterator().next();
    id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs", id, "wrong id for field :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToField(Chair.class.getField("legs"), new ComfyChairLiteral());
    chair3 = builder.create();
    field = chair3.getFields().iterator().next();
    id = AnnotatedTypes.createFieldId(field);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair.legs[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]",
        id,
        "wrong id for field :" + id);
  }
示例#2
0
  @Test
  public void testTypeId() throws SecurityException, NoSuchMethodException {
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    String id = AnnotatedTypes.createTypeId(chair3);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[@javax.enterprise.inject.Produces()]();}",
        id,
        "wrong id for type :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    chair3 = builder.create();
    id = AnnotatedTypes.createTypeId(chair3);
    Assert.assertEquals("org.jboss.weld.tests.unit.util.Chair{}", id, "wrong id for type :" + id);

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToMethod(Chair.class.getMethod("sit"), new ComfyChairLiteral());
    chair3 = builder.create();
    id = AnnotatedTypes.createTypeId(chair3);
    Assert.assertEquals(
        "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]();}",
        id,
        "wrong id for type :" + id);
  }
示例#3
0
  /** tests the AnnotatedTypes.compareAnnotatedTypes */
  @Test
  public void testComparison()
      throws SecurityException, NoSuchFieldException, NoSuchMethodException {
    // check that two weld classes on the same underlying are equal
    TypeStore ts = new TypeStore();
    String contextId = "STATIC_INSTANCE";
    ClassTransformer ct = new ClassTransformer(contextId, ts);
    WeldClass<Chair> chair1 = WeldClassImpl.of(contextId, Chair.class, ct);
    WeldClass<Chair> chair2 = WeldClassImpl.of(contextId, Chair.class, ct);
    Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair2));

    // check that a different implementation of annotated type is equal to the weld implementation
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new DefaultLiteral());
    builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));

    // check that the implementation returns false if a field annotation changes
    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new DefaultLiteral());
    builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    chair3 = builder.create();
    Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));

    // check that the implementation returns false if a class level annotation changes
    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new ProducesLiteral());
    builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    chair3 = builder.create();
    Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
  }
示例#4
0
  @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);
  }
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof MethodInjectionPoint<?, ?>) {
     MethodInjectionPoint<?, ?> ip = (MethodInjectionPoint<?, ?>) obj;
     if (AnnotatedTypes.compareAnnotatedCallable(method, ip.method)) {
       return true;
     }
   }
   return false;
 }
示例#6
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();
 }
示例#7
0
 public static String forProducerField(
     EnhancedAnnotatedField<?, ?> field, AbstractClassBean<?> declaringBean) {
   StringBuilder sb =
       getPrefix(ProducerField.class)
           .append(declaringBean.getAnnotated().getIdentifier().asString())
           .append(BEAN_ID_SEPARATOR);
   if (declaringBean.getEnhancedAnnotated().isDiscovered()) {
     sb.append(field.getName());
   } else {
     sb.append(AnnotatedTypes.createFieldId(field));
   }
   return sb.toString();
 }
示例#8
0
 private Object writeReplace() throws ObjectStreamException {
   return new UnbackedMemberIdentifier<X>(getDeclaringType(), AnnotatedTypes.createFieldId(this));
 }