1 package org.sonar.java.ast.check;
3 import static org.hamcrest.Matchers.is;
4 import static org.junit.Assert.assertThat;
5 import static org.sonar.java.ast.SquidTestUtils.getFile;
7 import org.junit.Before;
9 import org.sonar.java.ast.JavaAstScanner;
10 import org.sonar.java.squid.JavaSquidConfiguration;
11 import org.sonar.squid.Squid;
12 import org.sonar.squid.api.CheckMessage;
13 import org.sonar.squid.api.SourceFile;
15 public class MethodComplexityCheckTest {
20 squid = new Squid(new JavaSquidConfiguration());
21 MethodComplexityCheck check = new MethodComplexityCheck();
22 check.setThreshold(5);
23 squid.registerVisitor(check);
24 JavaAstScanner scanner = squid.register(JavaAstScanner.class);
25 scanner.scanFile(getFile("/metrics/branches/ComplexBranches.java"));
29 public void testMethodComplexityExceedsThreshold() {
30 SourceFile file = (SourceFile) squid.search("ComplexBranches.java");
31 assertThat(file.getCheckMessages().size(), is(1));
32 CheckMessage message = file.getCheckMessages().iterator().next();
33 assertThat(message.getLine(), is(10));