/** * {@inheritDoc} */ @Override protected boolean matches(ClassType classType) { return getClassSensorAssignmentFilter().matches(methodSensorAssignment, classType, false); }
/** * {@inheritDoc} */ @Override protected boolean matches(ClassType classType) { return classType.isException() && getClassSensorAssignmentFilter().matches(exceptionSensorAssignment, classType); }
@Test public void doesNotMatchClassFilter() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(classFilter.matches(assignment, classType, false)).thenReturn(false); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(false)); verifyZeroInteractions(registrationService, methodType); }
@Test public void doesNotMatchClassFilter() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(classFilter.matches(assignment, classType, false)).thenReturn(false); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(false)); verifyZeroInteractions(methodType); }
@Test public void name() { String name = "name"; when(assignment.getClassName()).thenReturn(name); when(classType.getFQN()).thenReturn(name); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(true)); when(classType.getFQN()).thenReturn("someOtherName"); assertThat(filter.matches(assignment, classType), is(false)); }
@Test public void nameWildCardNotMatching() { String wildCard = "nam*"; when(assignment.getClassName()).thenReturn(wildCard); when(classType.getFQN()).thenReturn("someOtherName"); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(false)); }
@Test public void doesNotMatchExceptionClass() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(classType.isException()).thenReturn(false); when(classFilter.matches(assignment, classType)).thenReturn(true); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType); // verify results assertThat(changed, is(false)); verifyZeroInteractions(registrationService, methodType); }
@Test public void nameNotMatching() { String name = "name"; when(assignment.getClassName()).thenReturn(name); when(classType.getFQN()).thenReturn("someOtherName"); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(false)); }
@Test public void nameWildCard() { String wildCard = "nam*"; when(assignment.getClassName()).thenReturn(wildCard); when(classType.getFQN()).thenReturn("name"); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(true)); }
@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); }
@BeforeMethod public void setup() { applier = new ExceptionSensorInstrumentationApplier(assignment, environment, registrationService); applier.assignmentFilterProvider = filterProvider; // filters to true by default when(filterProvider.getClassSensorAssignmentFilter()).thenReturn(classFilter); when(classFilter.matches(Matchers.<AbstractClassSensorAssignment<?>> any(), Matchers.<ClassType> any())).thenReturn(true); // class to return one method when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); }
@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)); }
@Test public void annotationNotChecked() { String name = "name"; when(assignment.getClassName()).thenReturn("*"); when(assignment.getAnnotation()).thenReturn(name); ImmutableAnnotationType annotation = Mockito.mock(ImmutableAnnotationType.class); when(annotation.getFQN()).thenReturn("someOtherName"); when(classType.getFQN()).thenReturn("someOtherName"); doReturn(Collections.singleton(annotation)).when(classType).getImmutableAnnotations(); boolean matches = filter.matches(assignment, classType, false); assertThat(matches, is(true)); }
@Test public void annotationWildCard() { String name = "n*me"; when(assignment.getClassName()).thenReturn("*"); when(assignment.getAnnotation()).thenReturn(name); ImmutableAnnotationType annotation = Mockito.mock(ImmutableAnnotationType.class); when(annotation.getFQN()).thenReturn(name); when(classType.getFQN()).thenReturn("someOtherName"); doReturn(Collections.singleton(annotation)).when(classType).getImmutableAnnotations(); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(true)); }
@Test public void annotationWildCardNotMatching() { String name = "n*me"; when(assignment.getClassName()).thenReturn("*"); when(assignment.getAnnotation()).thenReturn(name); ImmutableAnnotationType annotation = Mockito.mock(ImmutableAnnotationType.class); when(annotation.getFQN()).thenReturn("someOtherName"); when(classType.getFQN()).thenReturn("someOtherName"); doReturn(Collections.singleton(annotation)).when(classType).getImmutableAnnotations(); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(false)); }
@Test public void annotationNotMatching() { String name = "name"; when(assignment.getClassName()).thenReturn("*"); when(assignment.getAnnotation()).thenReturn(name); ImmutableAnnotationType annotation = Mockito.mock(ImmutableAnnotationType.class); when(annotation.getFQN()).thenReturn("someOtherName"); when(classType.getFQN()).thenReturn("someOtherName"); doReturn(Collections.singleton(annotation)).when(classType).getImmutableAnnotations(); boolean matches = filter.matches(assignment, classType); assertThat(matches, is(false)); }
@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 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 doesNotMatchClassFilter() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.isException()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType)).thenReturn(false); when(methodType.getName()).thenReturn("<init>"); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(false)); verify(methodType, times(0)).setMethodInstrumentationConfig(Matchers.<MethodInstrumentationConfig> any()); }
@Test public void doesNotMatchConstructorMethod() { when(classType.hasInstrumentationPoints()).thenReturn(true); when(classType.isException()).thenReturn(true); when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classFilter.matches(assignment, classType)).thenReturn(true); when(methodType.getName()).thenReturn("whatever"); boolean removed = applier.removeInstrumentationPoints(classType); assertThat(removed, is(false)); verify(methodType, times(0)).setMethodInstrumentationConfig(Matchers.<MethodInstrumentationConfig> any()); } }