Skip to content

Commit

Permalink
Fixed more tests that fail on Java 9.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 19, 2016
1 parent 97881e6 commit c9b2c82
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
Expand Up @@ -2986,12 +2986,8 @@ protected ForInlining(TypeDescription instrumentedType,
@Override
protected UnresolvedType create(TypeInitializer typeInitializer) {
try {
ClassFileLocator.Resolution resolution = classFileLocator.locate(originalType.getName());
if (!resolution.isResolved()) {
throw new IllegalArgumentException("Cannot locate the class file for " + originalType + " using " + classFileLocator);
}
int writerFlags = asmVisitorWrapper.mergeWriter(AsmVisitorWrapper.NO_FLAGS), readerFlags = asmVisitorWrapper.mergeReader(AsmVisitorWrapper.NO_FLAGS);
ClassReader classReader = new ClassReader(resolution.resolve());
ClassReader classReader = new ClassReader(classFileLocator.locate(originalType.getName()).resolve());
ClassWriter classWriter = new FrameComputingClassWriter(classReader, writerFlags, typePool);
ContextRegistry contextRegistry = new ContextRegistry();
classReader.accept(writeTo(asmVisitorWrapper.wrap(instrumentedType,
Expand Down
@@ -1,6 +1,7 @@
package net.bytebuddy.description.method;

import net.bytebuddy.test.utility.ObjectPropertyAssertion;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.AccessibleObject;
Expand All @@ -14,19 +15,26 @@ public class ParameterDescriptionForLoadedParameterDispatcherTest {

private static final int FOO = 42;

private AccessibleObject accessibleObject;

@Before
public void setUp() throws Exception {
accessibleObject = Foo.class.getDeclaredConstructor();
}

@Test(expected = IllegalStateException.class)
public void testLegacyVmGetName() throws Exception {
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.getName(mock(AccessibleObject.class), FOO);
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.getName(accessibleObject, FOO);
}

@Test(expected = IllegalStateException.class)
public void testLegacyVmGetModifiers() throws Exception {
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.getModifiers(mock(AccessibleObject.class), FOO);
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.getModifiers(accessibleObject, FOO);
}

@Test(expected = IllegalStateException.class)
public void testLegacyVmIsNamePresent() throws Exception {
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.isNamePresent(mock(AccessibleObject.class), FOO);
ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.INSTANCE.isNamePresent(accessibleObject, FOO);
}

@Test
Expand All @@ -40,4 +48,8 @@ public Method create() {
}).apply();
ObjectPropertyAssertion.of(ParameterDescription.ForLoadedParameter.Dispatcher.ForLegacyVm.class).apply();
}

private static class Foo {
/* empty */
}
}
Expand Up @@ -4,6 +4,7 @@
import net.bytebuddy.utility.CompoundList;
import org.junit.Test;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
Expand Down Expand Up @@ -113,7 +114,13 @@ public Class<?> create() {
return types.next();
}
}).apply();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedParameterizedType.class).apply();
final Iterator<AccessibleObject> iterator = Arrays.<AccessibleObject>asList(Object.class.getDeclaredMethods()).iterator();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedParameterizedType.class).create(new ObjectPropertyAssertion.Creator<AccessibleObject>() {
@Override
public AccessibleObject create() {
return iterator.next();
}
}).apply();
final Iterator<Method> methods2 = Arrays.asList(Object.class.getDeclaredMethods()).iterator();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedReturnType.class)
.create(new ObjectPropertyAssertion.Creator<Method>() {
Expand All @@ -131,6 +138,11 @@ public Class<?> create() {
}
}).apply();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedTypeVariableType.class).apply();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedExceptionType.class).apply();
ObjectPropertyAssertion.of(TypeDescription.Generic.AnnotationReader.Dispatcher.ForJava8CapableVm.AnnotatedExceptionType.class).create(new ObjectPropertyAssertion.Creator<AccessibleObject>() {
@Override
public AccessibleObject create() {
return iterator.next();
}
}).apply();
}
}
Expand Up @@ -472,8 +472,9 @@ public void testBridgeNonLegacyType() throws Exception {
@Test
public void testNoBridgeLegacyType() throws Exception {
Class<?> base = new ByteBuddy(ClassFileVersion.JAVA_V4)
.subclass(Object.class)
.subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS)
.modifiers(Visibility.PACKAGE_PRIVATE)
.defineConstructor(Visibility.PUBLIC).intercept(SuperMethodCall.INSTANCE)
.defineMethod("foo", void.class, Visibility.PUBLIC).intercept(StubMethod.INSTANCE)
.defineMethod("bar", Object.class).intercept(StubMethod.INSTANCE)
.defineMethod("bar", String.class).intercept(StubMethod.INSTANCE)
Expand Down
Expand Up @@ -3,6 +3,7 @@
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.test.scope.EnclosingType;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -54,7 +55,7 @@ public TypeWriterModifierPreservationTest(Class<?> type) {
@Test
public void testModifiers() throws Exception {
TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor();
new ClassReader(type.getName()).accept(typeModifierExtractor, 0);
new ClassReader(ClassFileLocator.ForClassLoader.read(type).resolve()).accept(typeModifierExtractor, 0);
new ByteBuddy()
.redefine(type)
.visit(new TypeValidator.Wrapper(typeModifierExtractor))
Expand Down

0 comments on commit c9b2c82

Please sign in to comment.