GroovySensor implements Sensor { @Override public void execute(SensorContext context) { if (groovyFileSystem.hasGroovyFiles()) { List<InputFile> inputFiles = groovyFileSystem.sourceInputFiles(); computeBaseMetrics(context, inputFiles); computeGroovyMetrics(context, inputFiles); highlightFiles(context, groovyFileSystem.groovyInputFiles()); } } GroovySensor(Settings settings, FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); @Override String toString();  }
@Test public void do_nothing_when_no_groovy_file() throws IOException { SensorContextTester context = SensorContextTester.create(new File("")); context = Mockito.spy(context); sensor = new GroovySensor(settings, fileLinesContextFactory, context.fileSystem()); sensor.execute(context); Mockito.verify(context, Mockito.never()).newHighlighting(); }
@Test public void compute_coupling_metrics() throws IOException { SensorContextTester context = SensorContextTester.create(new File("")); fileSystem = context.fileSystem(); DefaultInputDir org = addFileWithParentFolder("src/test/resources/org/sonar/plugins/groovy/gmetricswithcoupling/org", "Greeting.groovy"); DefaultInputDir org_foo = addFileWithParentFolder("src/test/resources/org/sonar/plugins/groovy/gmetricswithcoupling/org/foo", "Foo.groovy"); DefaultInputDir org_bar = addFileWithParentFolder("src/test/resources/org/sonar/plugins/groovy/gmetricswithcoupling/org/bar", "Bar.groovy"); FileLinesContext fileLinesContext = mock(FileLinesContext.class); when(fileLinesContextFactory.createFor(any(DefaultInputFile.class))).thenReturn(fileLinesContext); sensor = new GroovySensor(settings, fileLinesContextFactory, fileSystem); sensor.execute(context); assertCouplingMeasureAre(context, org.key(), 3, 1.0, 3, 1.0); assertCouplingMeasureAre(context, org_foo.key(), 1, 1.0, 1, 1.0); assertCouplingMeasureAre(context, org_bar.key(), 2, 2.0, 0, 0.0); }