ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon DependencyMetricsTest.java
Date Thu, 07 Feb 2002 09:24:35 GMT
donaldp     02/02/07 01:24:35

  Modified:    proposal/myrmidon/src/testcases/org/apache/myrmidon
                        DependencyMetricsTest.java
  Log:
  Refactored dependecy tests so that myrmidon can not depend on antlib or the old ant tree.
  
  Revision  Changes    Path
  1.2       +73 -27    jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/DependencyMetricsTest.java
  
  Index: DependencyMetricsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/DependencyMetricsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DependencyMetricsTest.java	2 Feb 2002 07:12:08 -0000	1.1
  +++ DependencyMetricsTest.java	7 Feb 2002 09:24:35 -0000	1.2
  @@ -20,7 +20,7 @@
    * fall in acceptable limits.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/02/02 07:12:08 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/07 09:24:35 $
    */
   public class DependencyMetricsTest
       extends TestCase
  @@ -145,37 +145,44 @@
        */
       public void testAutDecoupled()
       {
  -        final JDepend jDepend = getJDepend();
  -        final Collection packageSet = jDepend.getPackages();
  -
  -        final Iterator packages = packageSet.iterator();
  -        while( packages.hasNext() )
  +        final String packageName = "org.apache.aut";
  +        final String[] badEfferents = new String[]
           {
  -            final JavaPackage javaPackage = (JavaPackage)packages.next();
  -            final String name = javaPackage.getName();
  -            if( !name.startsWith( "org.apache.aut" ) )
  -            {
  -                continue;
  -            }
  +            "org.apache.myrmidon", "org.apache.antlib", "org.apache.tools.ant"
  +        };
  +        doTestDecoupled( packageName, badEfferents );
  +    }
   
  -            final Collection efferentSet = javaPackage.getEfferents();
  -            final Iterator efferents = efferentSet.iterator();
  -            while( efferents.hasNext() )
  -            {
  -                final JavaPackage efferent = (JavaPackage)efferents.next();
  -                final String efferentName = efferent.getName();
  -                if( efferentName.startsWith( "org.apache.myrmidon" ) ||
  -                    efferentName.startsWith( "org.apache.antlib" ) ||
  -                    efferentName.startsWith( "org.apache.tools.ant" ) )
  -                {
  -                    fail( "The package " + name + " depends on classes " +
  -                          "contained in " + efferentName );
  -                }
  -            }
  -        }
  +    /**
  +     * Make sure that myrmidon package does not have any
  +     * unwanted dependencies.
  +     */
  +    public void testMyrmidonDecoupled()
  +    {
  +        final String packageName = "org.apache.myrmidon";
  +        final String[] badEfferents = new String[]
  +        {
  +            "org.apache.antlib", "org.apache.tools.ant"
  +        };
  +        doTestDecoupled( packageName, badEfferents );
       }
   
       /**
  +     * Make sure that antlib package does not have any
  +     * unwanted dependencies.
  +     */
  +/*
  +    public void testAntlibDecoupled()
  +    {
  +        final String packageName = "org.apache.antlib";
  +        final String[] badEfferents = new String[]
  +        {
  +            "org.apache.tools.ant"
  +        };
  +        doTestDecoupled( packageName, badEfferents );
  +    }
  +*/
  +    /**
        * Make sure there are no circular dependencies between packages because
        * circular dependencies are evil!!!
        */
  @@ -211,5 +218,44 @@
           }
   
           return names;
  +    }
  +
  +    /**
  +     * Make sure that the specified package does not depend on any
  +     * of the specified package hierarchies.
  +     */
  +    private void doTestDecoupled( final String packageName,
  +                                  final String[] invalidEfferents )
  +    {
  +        final JDepend jDepend = getJDepend();
  +        final Collection packageSet = jDepend.getPackages();
  +
  +        final Iterator packages = packageSet.iterator();
  +        while( packages.hasNext() )
  +        {
  +            final JavaPackage javaPackage = (JavaPackage)packages.next();
  +            final String name = javaPackage.getName();
  +            if( !name.startsWith( packageName ) )
  +            {
  +                continue;
  +            }
  +
  +            final Collection efferentSet = javaPackage.getEfferents();
  +            final Iterator efferents = efferentSet.iterator();
  +            while( efferents.hasNext() )
  +            {
  +                final JavaPackage efferent = (JavaPackage)efferents.next();
  +                final String efferentName = efferent.getName();
  +                for( int i = 0; i < invalidEfferents.length; i++ )
  +                {
  +                    final String other = invalidEfferents[ i ];
  +                    if( efferentName.startsWith( other ) )
  +                    {
  +                        fail( "The package " + name + " has an unwanted dependency " +
  +                              "on classes contained in " + efferentName );
  +                    }
  +                }
  +            }
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message