Skip to content

Commit

Permalink
Refactored test for rebase implementation target.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jul 21, 2015
1 parent 037aa5d commit 64216eb
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 174 deletions.
@@ -1,6 +1,7 @@
package net.bytebuddy.description.field; package net.bytebuddy.description.field;


import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
Expand Down Expand Up @@ -366,7 +367,7 @@ public InDeclaredForm asDeclared() {
* A token that represents a field's shape. A field token is equal to another token when the other field * A token that represents a field's shape. A field token is equal to another token when the other field
* tokens's name is equal to this token. * tokens's name is equal to this token.
*/ */
class Token implements ByteCodeElement.Token<Token> { class Token extends ModifierReviewable.AbstractModifierReviewable implements ByteCodeElement.Token<Token> {


/** /**
* The name of the represented field. * The name of the represented field.
Expand Down Expand Up @@ -432,11 +433,7 @@ public GenericTypeDescription getType() {
return type; return type;
} }


/** @Override
* Returns the modifiers of the represented field.
*
* @return The modifiers of the represented field.
*/
public int getModifiers() { public int getModifiers() {
return modifiers; return modifiers;
} }
Expand Down
@@ -1,6 +1,7 @@
package net.bytebuddy.description.method; package net.bytebuddy.description.method;


import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
Expand Down Expand Up @@ -1294,7 +1295,7 @@ public String getSymbol() {
* A token that represents a method's shape. A method token is equal to another token when the name, the raw return type * A token that represents a method's shape. A method token is equal to another token when the name, the raw return type
* and the raw parameter types are equal to those of another method token. * and the raw parameter types are equal to those of another method token.
*/ */
class Token implements ByteCodeElement.Token<Token> { class Token extends ModifierReviewable.AbstractModifierReviewable implements ByteCodeElement.Token<Token> {


/** /**
* The internal name of the represented method. * The internal name of the represented method.
Expand Down Expand Up @@ -1394,11 +1395,7 @@ public String getInternalName() {
return internalName; return internalName;
} }


/** @Override
* Returns the modifiers of the represented method.
*
* @return The modifiers of the represented method.
*/
public int getModifiers() { public int getModifiers() {
return modifiers; return modifiers;
} }
Expand Down
Expand Up @@ -62,7 +62,7 @@ protected Implementation.SpecialMethodInvocation invokeSuper(MethodDescription m
*/ */
private Implementation.SpecialMethodInvocation invokeSuper(MethodRebaseResolver.Resolution resolution) { private Implementation.SpecialMethodInvocation invokeSuper(MethodRebaseResolver.Resolution resolution) {
return resolution.isRebased() return resolution.isRebased()
? RebasedMethodSpecialMethodInvocation.of(resolution, typeDescription) ? RebasedMethodInvocation.of(resolution, typeDescription)
: Implementation.SpecialMethodInvocation.Simple.of(resolution.getResolvedMethod(), typeDescription); : Implementation.SpecialMethodInvocation.Simple.of(resolution.getResolvedMethod(), typeDescription);
} }


Expand Down Expand Up @@ -97,7 +97,7 @@ public String toString() {
* A {@link Implementation.SpecialMethodInvocation} which invokes a rebased method * A {@link Implementation.SpecialMethodInvocation} which invokes a rebased method
* as given by a {@link MethodRebaseResolver}. * as given by a {@link MethodRebaseResolver}.
*/ */
protected static class RebasedMethodSpecialMethodInvocation implements Implementation.SpecialMethodInvocation { protected static class RebasedMethodInvocation implements Implementation.SpecialMethodInvocation {


/** /**
* The method to invoke via a special method invocation. * The method to invoke via a special method invocation.
Expand All @@ -120,7 +120,7 @@ protected static class RebasedMethodSpecialMethodInvocation implements Implement
* @param resolution The resolution of the rebased method. * @param resolution The resolution of the rebased method.
* @param instrumentedType The instrumented type on which this method is to be invoked. * @param instrumentedType The instrumented type on which this method is to be invoked.
*/ */
protected RebasedMethodSpecialMethodInvocation(MethodRebaseResolver.Resolution resolution, TypeDescription instrumentedType) { protected RebasedMethodInvocation(MethodRebaseResolver.Resolution resolution, TypeDescription instrumentedType) {
this.instrumentedType = instrumentedType; this.instrumentedType = instrumentedType;
methodDescription = resolution.getResolvedMethod(); methodDescription = resolution.getResolvedMethod();
stackManipulation = new Compound(resolution.getAdditionalArguments(), resolution.getResolvedMethod().isStatic() stackManipulation = new Compound(resolution.getAdditionalArguments(), resolution.getResolvedMethod().isStatic()
Expand All @@ -139,7 +139,7 @@ protected RebasedMethodSpecialMethodInvocation(MethodRebaseResolver.Resolution r
public static Implementation.SpecialMethodInvocation of(MethodRebaseResolver.Resolution resolution, TypeDescription instrumentedType) { public static Implementation.SpecialMethodInvocation of(MethodRebaseResolver.Resolution resolution, TypeDescription instrumentedType) {
return resolution.getResolvedMethod().isAbstract() return resolution.getResolvedMethod().isAbstract()
? Illegal.INSTANCE ? Illegal.INSTANCE
: new RebasedMethodSpecialMethodInvocation(resolution, instrumentedType); : new RebasedMethodInvocation(resolution, instrumentedType);
} }


@Override @Override
Expand Down Expand Up @@ -185,7 +185,7 @@ public int hashCode() {


@Override @Override
public String toString() { public String toString() {
return "RebaseimplementationTarget.RedefinedConstructorInvocation{" + return "RebaseimplementationTarget.RebasedMethodInvocation{" +
"instrumentedType=" + instrumentedType + "instrumentedType=" + instrumentedType +
", methodDescription=" + methodDescription + ", methodDescription=" + methodDescription +
'}'; '}';
Expand Down
Expand Up @@ -158,9 +158,7 @@ class Simple implements SpecialMethodInvocation {
* invocation. * invocation.
* @param stackManipulation The stack manipulation that represents this special method invocation. * @param stackManipulation The stack manipulation that represents this special method invocation.
*/ */
protected Simple(MethodDescription methodDescription, protected Simple(MethodDescription methodDescription, TypeDescription typeDescription, StackManipulation stackManipulation) {
TypeDescription typeDescription,
StackManipulation stackManipulation) {
this.methodDescription = methodDescription; this.methodDescription = methodDescription;
this.typeDescription = typeDescription; this.typeDescription = typeDescription;
this.stackManipulation = stackManipulation; this.stackManipulation = stackManipulation;
Expand All @@ -175,10 +173,9 @@ protected Simple(MethodDescription methodDescription,
* @return A special method invocation representing a legal invocation if the method can be invoked * @return A special method invocation representing a legal invocation if the method can be invoked
* specially on the target type or an illegal invocation if this is not possible. * specially on the target type or an illegal invocation if this is not possible.
*/ */
public static SpecialMethodInvocation of(MethodDescription methodDescription, public static SpecialMethodInvocation of(MethodDescription methodDescription, TypeDescription typeDescription) {
TypeDescription typeDescription) {
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).special(typeDescription); StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).special(typeDescription);
return stackManipulation.isValid() && !methodDescription.isAbstract() return stackManipulation.isValid()
? new Simple(methodDescription, typeDescription, stackManipulation) ? new Simple(methodDescription, typeDescription, stackManipulation)
: SpecialMethodInvocation.Illegal.INSTANCE; : SpecialMethodInvocation.Illegal.INSTANCE;
} }
Expand Down
Expand Up @@ -3,6 +3,7 @@
import net.bytebuddy.test.utility.MockitoRule; import net.bytebuddy.test.utility.MockitoRule;
import net.bytebuddy.test.utility.ObjectPropertyAssertion; import net.bytebuddy.test.utility.ObjectPropertyAssertion;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void testMultipleParentClassLoadingNotFound() throws Exception {
} }


@Test @Test
@Ignore("This test takes too much time: find out why.")
public void testMultipleParentURL() throws Exception { public void testMultipleParentURL() throws Exception {
ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build(); ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build();
assertThat(classLoader.getResource(FOO), is(fooUrl)); assertThat(classLoader.getResource(FOO), is(fooUrl));
Expand All @@ -108,6 +110,7 @@ public void testMultipleParentURLNotFound() throws Exception {
} }


@Test @Test
@Ignore("This test takes too much time: find out why.")
public void testMultipleParentEnumerationURL() throws Exception { public void testMultipleParentEnumerationURL() throws Exception {
ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build(); ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build();
Enumeration<URL> foo = classLoader.getResources(FOO); Enumeration<URL> foo = classLoader.getResources(FOO);
Expand Down
Expand Up @@ -18,7 +18,6 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -56,7 +55,7 @@ protected Implementation.SpecialMethodInvocation make(String name,
when(methodDescription.getDeclaringType()).thenReturn(declaringType); when(methodDescription.getDeclaringType()).thenReturn(declaringType);
when(methodDescription.asDeclared()).thenReturn(methodDescription); when(methodDescription.asDeclared()).thenReturn(methodDescription);
when(resolution.getResolvedMethod()).thenReturn(methodDescription); when(resolution.getResolvedMethod()).thenReturn(methodDescription);
return new RebaseImplementationTarget.RebasedMethodSpecialMethodInvocation(resolution, targetType); return new RebaseImplementationTarget.RebasedMethodInvocation(resolution, targetType);
} }


@Test @Test
Expand All @@ -74,7 +73,7 @@ public void testIsValid() throws Exception {
Collections.<GenericTypeDescription>emptyList(), Collections.<GenericTypeDescription>emptyList(),
Collections.<AnnotationDescription>emptyList(), Collections.<AnnotationDescription>emptyList(),
MethodDescription.NO_DEFAULT_VALUE)); MethodDescription.NO_DEFAULT_VALUE));
Implementation.SpecialMethodInvocation specialMethodInvocation = new RebaseImplementationTarget.RebasedMethodSpecialMethodInvocation(resolution, Implementation.SpecialMethodInvocation specialMethodInvocation = new RebaseImplementationTarget.RebasedMethodInvocation(resolution,
mock(TypeDescription.class)); mock(TypeDescription.class));
assertThat(specialMethodInvocation.isValid(), is(true)); assertThat(specialMethodInvocation.isValid(), is(true));
} }
Expand All @@ -94,7 +93,7 @@ public void testIsInvalid() throws Exception {
Collections.<GenericTypeDescription>emptyList(), Collections.<GenericTypeDescription>emptyList(),
Collections.<AnnotationDescription>emptyList(), Collections.<AnnotationDescription>emptyList(),
MethodDescription.NO_DEFAULT_VALUE)); MethodDescription.NO_DEFAULT_VALUE));
Implementation.SpecialMethodInvocation specialMethodInvocation = new RebaseImplementationTarget.RebasedMethodSpecialMethodInvocation(resolution, Implementation.SpecialMethodInvocation specialMethodInvocation = new RebaseImplementationTarget.RebasedMethodInvocation(resolution,
mock(TypeDescription.class)); mock(TypeDescription.class));
assertThat(specialMethodInvocation.isValid(), is(false)); assertThat(specialMethodInvocation.isValid(), is(false));
} }
Expand Down

0 comments on commit 64216eb

Please sign in to comment.