diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java index 74ed47d5a..d07ac0aca 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2005 Oliver Burn +// Copyright (C) 2001-2007 Oliver Burn // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ import com.puppycrawl.tools.checkstyle.checks.CheckUtils; import java.util.HashSet; import java.util.Set; import java.util.Stack; +import java.util.TreeSet; /** * Base class for coupling calculation. @@ -202,8 +203,11 @@ public abstract class AbstractClassCouplingCheck extends Check */ private class Context { - /** Set of referenced classes. */ - private final Set mReferencedClassNames = new HashSet(); + /** + * Set of referenced classes. + * Sorted by name for predictable error messages in unit tests. + */ + private final Set mReferencedClassNames = new TreeSet(); /** Own class name. */ private final String mClassName; /* Location of own class. (Used to log violations) */ diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java index ea4feb846..78bbd63f5 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/metrics/ClassDataAbstractionCouplingCheckTest.java @@ -14,7 +14,7 @@ public class ClassDataAbstractionCouplingCheckTest extends BaseCheckTestCase checkConfig.addAttribute("max", "0"); String[] expected = { - "6:1: Class Data Abstraction Coupling is 4 (max allowed is 0) classes [AnotherInnerClass, HashMap, InnerClass, HashSet].", + "6:1: Class Data Abstraction Coupling is 4 (max allowed is 0) classes [AnotherInnerClass, HashMap, HashSet, InnerClass].", "7:5: Class Data Abstraction Coupling is 1 (max allowed is 0) classes [ArrayList].", "27:1: Class Data Abstraction Coupling is 2 (max allowed is 0) classes [HashMap, HashSet].", };