Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Nov 1, 2024
1 parent abcda7d commit 115a460
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

import java.lang.annotation.Annotation;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -75,25 +73,26 @@ public void testPrematureApplication() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public void testMinimalRegistrationIndependentType() throws Exception {
Annotation eagerAnnotation = mock(AuxiliaryType.SignatureRelevant.class);
when(eagerAnnotation.annotationType()).thenReturn((Class) AuxiliaryType.SignatureRelevant.class);
TypeDescription independent = mock(TypeDescription.class), dependent = mock(TypeDescription.class);
when(independent.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(eagerAnnotation));
when(dependent.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
Map<TypeDescription, byte[]> map = new HashMap<TypeDescription, byte[]>();
map.put(independent, QUX);
map.put(dependent, BAZ);
when(dynamicType.getAuxiliaryTypes()).thenReturn(map);
when(dynamicType.getAuxiliaryTypeDescriptions()).thenReturn(new HashSet<TypeDescription>(Arrays.asList(independent, dependent)));
Map<TypeDescription, byte[]> auxiliaryTypes = new HashMap<TypeDescription, byte[]>();
auxiliaryTypes.put(independent, QUX);
auxiliaryTypes.put(dependent, BAZ);
when(dynamicType.getAuxiliaryTypes()).thenReturn(auxiliaryTypes);
ClassInjector classInjector = mock(ClassInjector.class);
when(injectionStrategy.resolve(classLoader, protectionDomain)).thenReturn(classInjector);
when(classInjector.inject(Collections.singletonMap(independent, QUX)))
when(classInjector.inject(Collections.singleton(independent), dynamicType))
.thenReturn(Collections.<TypeDescription, Class<?>>singletonMap(independent, Foo.class));
LoadedTypeInitializer loadedTypeInitializer = mock(LoadedTypeInitializer.class);
when(dynamicType.getLoadedTypeInitializers()).thenReturn(Collections.singletonMap(independent, loadedTypeInitializer));
AgentBuilder.InitializationStrategy.Minimal.INSTANCE.register(dynamicType, classLoader, protectionDomain, injectionStrategy);
verify(classInjector).inject(Collections.singletonMap(independent, QUX));
verify(classInjector).inject(Collections.singleton(independent), dynamicType);
verifyNoMoreInteractions(classInjector);
verify(loadedTypeInitializer).onLoad(Foo.class);
verifyNoMoreInteractions(loadedTypeInitializer);
Expand Down

0 comments on commit 115a460

Please sign in to comment.