/** 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();
    ClassTransformer ct = new ClassTransformer(ts);
    WeldClass<Chair> chair1 = WeldClassImpl.of(Chair.class, ct);
    WeldClass<Chair> chair2 = WeldClassImpl.of(Chair.class, ct);
    assert 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 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 !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 !AnnotatedTypes.compareAnnotatedTypes(chair1, chair3);
  }
  @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 "org.jboss.weld.tests.unit.util.Chair.sit[@javax.enterprise.inject.Produces()]()"
            .equals(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 "org.jboss.weld.tests.unit.util.Chair.sit()".equals(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 "org.jboss.weld.tests.unit.util.Chair.sit[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]()"
            .equals(id)
        : "wrong id for method :" + id;
  }
  @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 "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[@javax.enterprise.inject.Produces()]();}"
            .equals(id)
        : "wrong id for type :" + id;

    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    chair3 = builder.create();
    id = AnnotatedTypes.createTypeId(chair3);
    assert "org.jboss.weld.tests.unit.util.Chair{}".equals(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 "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[@org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]();}"
            .equals(id)
        : "wrong id for type :" + id;
  }