@Test public void removeNothing() { // nothing to remove when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classType.hasInstrumentationPoints()).thenReturn(false); boolean result = applier.removeInstrumentationPoints(classType); assertThat(result, is(false)); verifyZeroInteractions(methodType); } }
/** * Checks if the {@link SensorInstrumentationPoint} exists in the * {@link MethodInstrumentationConfig}. If not new one is created, registered with registration * service and saved in the {@link MethodInstrumentationConfig}. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return {@link SensorInstrumentationPoint} for the {@link MethodInstrumentationConfig}. */ protected SpecialInstrumentationPoint getOrCreateSpecialInstrumentationPoint(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // check for existing SpecialInstrumentationPoint specialInstrumentationPoint = methodInstrumentationConfig.getSpecialInstrumentationPoint(); // if not create new one if (null == specialInstrumentationPoint) { // if not create new and register long id = registerMethod(agentConfiguration, methodType, methodInstrumentationConfig); specialInstrumentationPoint = new SpecialInstrumentationPoint(); specialInstrumentationPoint.setId(id); // set to method instrumentation methodInstrumentationConfig.setSpecialInstrumentationPoint(specialInstrumentationPoint); } return specialInstrumentationPoint; }
when(methodType.getModifiers()).thenReturn(mod); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType);
/** * Checks if the {@link SensorInstrumentationPoint} exists in the * {@link MethodInstrumentationConfig}. If not new one is created, registered with registration * service and saved in the {@link MethodInstrumentationConfig}. * * @param agentConfiguration * {@link AgentConfig} to read platform id. * @param methodType * {@link MethodType} in question. * @param methodInstrumentationConfig * {@link MethodInstrumentationConfig}. * @return {@link SensorInstrumentationPoint} for the {@link MethodInstrumentationConfig}. */ protected SensorInstrumentationPoint getOrCreateSensorInstrumentationPoint(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // check for existing SensorInstrumentationPoint sensorInstrumentationPoint = methodInstrumentationConfig.getSensorInstrumentationPoint(); // if not create new one if (null == sensorInstrumentationPoint) { // if not create new and register long id = registerMethod(agentConfiguration, methodType, methodInstrumentationConfig); sensorInstrumentationPoint = new SensorInstrumentationPoint(); sensorInstrumentationPoint.setId(id); if (Character.CONSTRUCTOR.equals(methodType.getMethodCharacter())) { sensorInstrumentationPoint.setConstructor(true); } // set to method instrumentation methodInstrumentationConfig.setSensorInstrumentationPoint(sensorInstrumentationPoint); } return sensorInstrumentationPoint; }
when(methodType.getModifiers()).thenReturn(mod); boolean changed = applier.addInstrumentationPoints(agentConfiguration, classType);
@Test public void remove() { // something to remove when(classType.getMethods()).thenReturn(Collections.singleton(methodType)); when(classType.hasInstrumentationPoints()).thenReturn(true); boolean result = applier.removeInstrumentationPoints(classType); assertThat(result, is(true)); verify(methodType, times(1)).setMethodInstrumentationConfig(null); }