From 0d393b6d32bbdb3ad52dc24c0978dd71b8e2482a Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 19 Apr 2016 22:02:34 +0200 Subject: [PATCH] Added additional test. --- .../builder/AgentBuilderDefaultTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultTest.java index 664706e76b1..3651d4aa6b2 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultTest.java @@ -147,6 +147,10 @@ public void testSuccessfulWithoutExistingClass() throws Exception { REDEFINED.getProtectionDomain(), accessControlContext)); verifyNoMoreInteractions(dispatcher); + verify(rawMatcher).matches(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), null, REDEFINED.getProtectionDomain()); + verifyNoMoreInteractions(rawMatcher); + verify(transformer).transform(builder, new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader()); + verifyNoMoreInteractions(transformer); } @Test @@ -923,6 +927,45 @@ public void testRetransformationConsiderationExceptionListenerException() throws verifyNoMoreInteractions(listener); } + @Test + public void testDecoratedTransformation() throws Exception { + when(dynamicType.getBytes()).thenReturn(BAZ); + when(resolution.resolve()).thenReturn(new TypeDescription.ForLoadedType(REDEFINED)); + when(rawMatcher.matches(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), null, REDEFINED.getProtectionDomain())) + .thenReturn(true); + ClassFileTransformer classFileTransformer = new AgentBuilder.Default(byteBuddy) + .with(initializationStrategy) + .with(binaryLocator) + .with(typeStrategy) + .with(listener) + .disableNativeMethodPrefix() + .with(accessControlContext) + .type(rawMatcher).transform(transformer) + .type(rawMatcher).transform(transformer).asDecorator() + .installOn(instrumentation); + assertThat(classFileTransformer.transform(REDEFINED.getClassLoader(), REDEFINED.getName(), null, REDEFINED.getProtectionDomain(), QUX), is(BAZ)); + verify(listener).onTransformation(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), dynamicType); + verify(listener).onComplete(REDEFINED.getName(), REDEFINED.getClassLoader());; + verifyNoMoreInteractions(listener); + verify(instrumentation).addTransformer(classFileTransformer, false); + verifyNoMoreInteractions(instrumentation); + verify(initializationStrategy).dispatcher(); + verifyNoMoreInteractions(initializationStrategy); + verify(dispatcher).apply(builder); + verify(dispatcher).register(dynamicType, + REDEFINED.getClassLoader(), + new AgentBuilder.Default.Transformation.Simple.Resolution.BootstrapClassLoaderCapableInjectorFactory( + AgentBuilder.Default.BootstrapInjectionStrategy.Disabled.INSTANCE, + REDEFINED.getClassLoader(), + REDEFINED.getProtectionDomain(), + accessControlContext)); + verifyNoMoreInteractions(dispatcher); + verify(rawMatcher, times(2)).matches(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), null, REDEFINED.getProtectionDomain()); + verifyNoMoreInteractions(rawMatcher); + verify(transformer, times(2)).transform(builder, new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader()); + verifyNoMoreInteractions(transformer); + } + @Test public void testBootstrapClassLoaderCapableInjectorFactoryReflection() throws Exception { AgentBuilder.Default.BootstrapInjectionStrategy bootstrapInjectionStrategy = mock(AgentBuilder.Default.BootstrapInjectionStrategy.class);