package net.bytebuddy.asm;

import net.bytebuddy.utility.OpenedClassReader;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class ClassVisitorFactoryOtherTest {

    private static final String FOO = "foo";

    @Test(expected = IllegalArgumentException.class)
    public void testInvalidInput() {
        ClassVisitorFactory.of(Object.class);
    }

    @Test
    public void testGetter() {
        assertThat(ClassVisitorFactory.of(ClassVisitor.class).getType(), is((Object) ClassVisitor.class));
    }

    @Test
    public void testAttributeWrapped() {
        final Attribute sample = new Attribute(FOO) {
            /* empty */
        };
        ClassVisitorFactory.of(ClassVisitor.class).wrap(new ClassVisitor(OpenedClassReader.ASM_API) {

            @Override
            public void visitAttribute(Attribute attribute) {
                assertThat(attribute, not(sameInstance(sample)));
                try {
                    assertThat(attribute.getClass().getField("delegate").get(attribute), sameInstance((Object) sample));
                } catch (Exception e) {
                    throw new AssertionError(e);
                }
            }
        }).visitAttribute(sample);
    }
}

@@ -823,24 +823,25 @@
 bute(FOO) %7B%0A
+%0A
             
@@ -844,19 +844,215 @@
     
-/* empty */
+@Override%0A            public boolean isUnknown() %7B%0A                return false;%0A            %7D%0A%0A            @Override%0A            public boolean isCodeAttribute() %7B%0A                return true;%0A            %7D
 %0A   
@@ -1308,24 +1308,206 @@
 (sample)));%0A
+                assertThat(attribute.type, is(FOO));%0A                assertThat(attribute.isUnknown(), is(false));%0A                assertThat(attribute.isCodeAttribute(), is(true));%0A
             

Extend attribute wrapper test.