SmellMeasuresSensor implements Sensor { @Override public void execute(final SensorContext context) { final List<InputFile> inputFiles = Lists.newArrayList(this.fileSystem.inputFiles(this.javaFilesPredicate)); final SmellMeasurer measurer = new SmellMeasurer(context); for (final InputFile inputFile : inputFiles) { measurer.measure(inputFile); } } SmellMeasuresSensor(final FileSystem fileSystem); @Override String toString(); @Override void describe(final SensorDescriptor descriptor); @Override void execute(final SensorContext context);  }
@Test public void analyse_should_saveMeasures() throws IOException { final SmellMeasuresSensor sut = new SmellMeasuresSensor(this.fs); final File testFile = new File("src/test/resources/SmellMeasuresSensorTest_1.java"); Mockito.when(this.fs.inputFiles(this.predicate)) .thenReturn(ImmutableList.<InputFile> of(this.inputFile)); Mockito.when(this.inputFile.file()) .thenReturn(testFile); Mockito.when(this.inputFile.absolutePath()) .thenReturn(testFile.getAbsolutePath()); Mockito.when(this.context.newMeasure()) .thenReturn(this.measure); Mockito.when(this.measure.forMetric(Mockito.any())) .thenReturn(this.measure); Mockito.when(this.measure.withValue(Mockito.any())) .thenReturn(this.measure); Mockito.when(this.measure.on(Mockito.any())) .thenReturn(this.measure); sut.execute(this.context); Mockito.verify(this.inputFile, Mockito.times(1)) .file(); final ArgumentCaptor<Metric> metricCaptor = ArgumentCaptor.forClass(Metric.class); final ArgumentCaptor<Serializable> valueCaptor = ArgumentCaptor.forClass(Serializable.class); Mockito.verify(this.context, Mockito.times(3)) .newMeasure(); Mockito.verify(this.measure, Mockito.times(3)) .save(); Mockito.verify(this.measure, Mockito.times(3)) .forMetric(metricCaptor.capture()); final List<Metric> capturedMetrics = metricCaptor.getAllValues(); assertEquals(SmellMetrics.SMELL_COUNT_ANTI_PATTERN, capturedMetrics.get(0)); assertEquals(SmellMetrics.SMELL_COUNT, capturedMetrics.get(1)); assertEquals(SmellMetrics.SMELL_DEBT, capturedMetrics.get(2)); Mockito.verify(this.measure, Mockito.times(3)) .withValue(valueCaptor.capture()); final List<Serializable> capturedValues = valueCaptor.getAllValues(); assertEquals(Integer.valueOf(7), capturedValues.get(0)); assertEquals(Integer.valueOf(7), capturedValues.get(1)); assertEquals(Long.valueOf(70), capturedValues.get(2)); Mockito.verify(this.measure, Mockito.times(3)) .on(Mockito.any()); Mockito.verifyNoMoreInteractions(this.context); }