File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -503,4 +503,47 @@ mod tests {
503503 ]
504504 ) ;
505505 }
506+
507+ // As reported here:
508+ // https://github.com/sebastianbergmann/php-code-coverage/issues/607
509+ // An anonymous class declaration is not considered when computing the Cyclomatic Complexity metric for Java
510+ // Only the complexity of the anonymous class content is considered for the computation
511+ #[ test]
512+ fn java_anonymous_class ( ) {
513+ check_metrics ! (
514+ "
515+ abstract class A { // +2 (+1 unit space)
516+ public abstract boolean m1(int n); // +1
517+ public abstract boolean m2(int n); // +1
518+ }
519+ public class B { // +1
520+
521+ public void test() { // +1
522+ A a = new A() {
523+ public boolean m1(int n) { // +1
524+ if (n % 2 == 0) { // +1
525+ return true;
526+ }
527+ return false;
528+ }
529+ public boolean m2(int n) { // +1
530+ if (n % 5 == 0) { // +1
531+ return true;
532+ }
533+ return false;
534+ }
535+ };
536+ }
537+ }" ,
538+ "foo.java" ,
539+ JavaParser ,
540+ cyclomatic,
541+ [ ( cyclomatic_sum, 10 , usize ) ] ,
542+ [
543+ ( cyclomatic_average, 1.25 ) , // nspace = 8 (unit, 2 classes and 5 methods)
544+ ( cyclomatic_max, 2.0 ) ,
545+ ( cyclomatic_min, 1.0 )
546+ ]
547+ ) ;
548+ }
506549}
You can’t perform that action at this time.
0 commit comments