/** * {@inheritDoc} */ @Override protected boolean matches(MethodType methodType) { return getMethodSensorAssignmentFilter().matches(methodSensorAssignment, methodType); }
/** * {@inheritDoc} * <p> * We only support method instrumentation with special assignments for now. No constructors of * any kind. */ @Override protected boolean matches(MethodType methodType) { return MethodType.Character.METHOD.equals(methodType.getMethodCharacter()) && getMethodSensorAssignmentFilter().matches(functionalAssignment, methodType); }
@Test public void doesNotMatchMethodFilter() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(methodFilter.matches(assignment, methodType)).thenReturn(false); // test direct and via collection // we expect two calls to everything boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(false)); verifyZeroInteractions(registrationService, methodType); }
@Test public void constructorNotMatchingAssignment() { when(assignment.isConstructor()).thenReturn(false); when(methodType.getMethodCharacter()).thenReturn(Character.CONSTRUCTOR); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(false)); }
@Test public void doesNotMatchMethodFilter() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(methodFilter.matches(assignment, methodType)).thenReturn(false); // test direct and via collection // we expect two calls to everything boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(false)); verify(methodType).getMethodCharacter(); verifyNoMoreInteractions(methodType); }
@Test public void constructorNotMatchingAssignmentWildcard() { when(assignment.getMethodName()).thenReturn("*"); when(assignment.isConstructor()).thenReturn(false); when(methodType.getMethodCharacter()).thenReturn(Character.CONSTRUCTOR); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(false)); }
@BeforeMethod public void setup() { applier = new MethodSensorInstrumentationApplier(assignment, environment, registrationService); applier.assignmentFilterProvider = filterProvider; // filters to true by default when(filterProvider.getClassSensorAssignmentFilter()).thenReturn(classFilter); when(filterProvider.getMethodSensorAssignmentFilter()).thenReturn(methodFilter); when(methodFilter.matches(Matchers.<MethodSensorAssignment> any(), Matchers.<MethodType> any())).thenReturn(true); when(classFilter.matches(Matchers.<AbstractClassSensorAssignment<?>> any(), Matchers.<ClassType> any(), Matchers.eq(false))).thenReturn(true); // class to return one method when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); }
@BeforeMethod public void setup() { applier = new InvocationStartMethodSensorInstrumentationApplier(assignment, environment, registrationService); applier.assignmentFilterProvider = filterProvider; // filters to true by default when(filterProvider.getClassSensorAssignmentFilter()).thenReturn(classFilter); when(filterProvider.getMethodSensorAssignmentFilter()).thenReturn(methodFilter); when(methodFilter.matches(Matchers.<MethodSensorAssignment> any(), Matchers.<MethodType> any())).thenReturn(true); when(classFilter.matches(Matchers.<AbstractClassSensorAssignment<?>> any(), Matchers.<ClassType> any(), Matchers.eq(false))).thenReturn(true); // class to return one method when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); }
@Test public void doesNotMatchClassFilter() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType, false)).thenReturn(false); when(methodFilter.matches(assignment, methodType)).thenReturn(true); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(false)); verifyZeroInteractions(methodType); }
@Test public void doesNotmatchClassFilter() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType, false)).thenReturn(false); when(methodFilter.matches(assignment, methodType)).thenReturn(true); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(false)); verifyZeroInteractions(methodType); }
@Test public void remove() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType, false)).thenReturn(true); when(methodFilter.matches(assignment, methodType)).thenReturn(true); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(true)); verify(methodType, times(1)).setMethodInstrumentationConfig(null); }
@Test public void remove() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType, false)).thenReturn(true); when(methodFilter.matches(assignment, methodType)).thenReturn(true); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(true)); verify(methodType, times(1)).setMethodInstrumentationConfig(null); }
@Test public void constructorNotMatchingMethodType() { // default when(assignment.isPublicModifier()).thenReturn(true); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PUBLIC)); // specific when(assignment.isConstructor()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(false)); }
@Test public void privateModifierNotMatching() { when(assignment.getMethodName()).thenReturn("*"); when(assignment.isPrivateModifier()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); when(methodType.getName()).thenReturn("name"); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PUBLIC)); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(false)); }
@Test public void protectedModifierNotMatching() { when(assignment.getMethodName()).thenReturn("*"); when(assignment.isProtectedModifier()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); when(methodType.getName()).thenReturn("name"); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PRIVATE)); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(false)); }
@Test public void base() { // default when(assignment.isPublicModifier()).thenReturn(true); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PUBLIC)); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); boolean result = filter.matches(assignment, methodType); assertThat(result, is(true)); }
@Test public void notMatchingStaticConstructor() { // default when(assignment.isPublicModifier()).thenReturn(true); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PUBLIC)); when(methodType.getMethodCharacter()).thenReturn(Character.STATIC_CONSTRUCTOR); boolean result = filter.matches(assignment, methodType); assertThat(result, is(false)); } }
@Test public void constructor() { // default when(assignment.isPublicModifier()).thenReturn(true); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PUBLIC)); // specific when(assignment.isConstructor()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.CONSTRUCTOR); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(true)); }
@Test public void protectedModifier() { when(assignment.getMethodName()).thenReturn("*"); when(assignment.isProtectedModifier()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); when(methodType.getName()).thenReturn("name"); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PROTECTED)); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(true)); }
@Test public void privateModifier() { when(assignment.getMethodName()).thenReturn("*"); when(assignment.isPrivateModifier()).thenReturn(true); when(methodType.getMethodCharacter()).thenReturn(Character.METHOD); when(methodType.getName()).thenReturn("name"); when(methodType.getModifiers()).thenReturn(Modifiers.getModifiers(Modifier.PRIVATE)); boolean matches = filter.matches(assignment, methodType); assertThat(matches, is(true)); }