ApexAstScanner { public static SourceFile scanFile(File file, SquidAstVisitor<Grammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException(String.format(FILE_NOT_FOUND, file)); } AstScanner<Grammar> scanner = create(new ApexConfiguration(Charsets.UTF_8), visitors); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException(String.format(ONE_SOURCE_FILE, sources.size())); } return (SourceFile) sources.iterator().next(); } private  ApexAstScanner(); static AstScanner<Grammar> create(ApexConfiguration config, SquidAstVisitor<Grammar>... visitors); static SourceFile scanFile(File file, SquidAstVisitor<Grammar>... visitors);  }
@Test public void testTheNumberOfScannedLines() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/lines.cls")); assertThat(sourceFile.getInt(ApexMetric.LINES)).isEqualTo(12); }
@Test public void testTheNumberOfScannedLinesOfCode() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/lines.cls")); assertThat(sourceFile.getInt(ApexMetric.LINES_OF_CODE)).isEqualTo(9); }
@Test public void testTheNumberOfScannedFunctions() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/methods.cls")); assertThat(sourceFile.getInt(ApexMetric.METHODS)).isEqualTo(2); }
@Test public void testTheNumberOfScannedStatements() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/statements.cls")); assertThat(sourceFile.getInt(ApexMetric.STATEMENTS)).isEqualTo(2); }
@Test public void testTheNumberOfScannedClasses() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/classes.cls")); assertThat(sourceFile.getInt(ApexMetric.CLASSES)).isEqualTo(2); }
@Test public void testTheNumberOfScannedComplexity() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/complexity.cls")); assertThat(sourceFile.getInt(ApexMetric.COMPLEXITY)).isEqualTo(3); }
@Test public void testTheNumberOfScannedComments() { sourceFile = ApexAstScanner.scanFile(new File("src/test/resources/metrics/comments.cls")); assertThat(sourceFile.getInt(ApexMetric.CLASSES)).isEqualTo(1); assertThat(sourceFile.getInt(ApexMetric.COMMENT_LINES)).isEqualTo(9); }