### Question:
CyclomaticComplexityFiller implements Filler { public void fill(InputFile file, SensorContext context, AntlrContext antlrContext) { try { DialectLanguageTypesMap types = antlrContext.types; ParseTree root = antlrContext.getRoot(); ClassTypesCountingVisitor visitor = new ClassTypesCountingVisitor(types.getCyclomaticComplexityClasses()); visitor.visit(root); synchronized (context) { context.<Integer>newMeasure().on(file).forMetric(CoreMetrics.COMPLEXITY) .withValue(visitor.getCounter() + 1).save(); } } catch (Throwable e) { LOGGER.warn("Error adding complexity measures on " + file, e); } }  void fill(InputFile file, SensorContext context, AntlrContext antlrContext);  }### Answer:
@Test public void testComplexity() throws IOException { SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.fileSystem().setWorkDir(folder.getRoot().toPath()); File baseFile = folder.newFile("test.sql"); FileUtils.copyURLToFile(getClass().getResource("/tsql/sample1.sql"), baseFile); String contents = new String(Files.readAllBytes(baseFile.toPath())); DefaultInputFile ti = new TestInputFileBuilder("test", folder.getRoot(), baseFile).initMetadata(contents) .setLanguage(Constants.languageKey).setContents(contents).setProjectBaseDir(folder.getRoot().toPath()) .build(); ctxTester.fileSystem().add(ti); AntlrContext antlrContext = dialect.parse( "SELECT case when t1.a = 2 then 1 else 0 end as x, now(), 1 from dbo.test as t1 left join dbo.test2 on t1.id = t2.id and t1.n = t2.n left join dbo.test as t3 on t1.id = t3.id" + " WHERE t1.name = 'aa' and t2.name = 'bb' " + " GROUP by t1.id, t2.name" + " HAVING COUNT(*) > 1 union all select * from dbo.test ORDER BY 1, 2;\r\n INSERT INTO dbo.test(a,b) VALUES (1,2);\r\n" + " DELETE FROM dbo.test; \r\n TRUNCATE TABLE x; \r\n UPDATE dbo.test set id = 1 where x = 4;\r\n"); filler.fill(ti, ctxTester, antlrContext); int cg = ctxTester.measure("test:test.sql", CoreMetrics.COMPLEXITY).value(); Assert.assertEquals("Complexity differs", expected, cg); }