alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (JavadocAssertionTestSuite.groovy)

This example Groovy source code file (JavadocAssertionTestSuite.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

class, collection, javadocassertiontestbuilder, javadocassertiontestbuilder, javadocassertiontestsuite, javadocassertiontestsuite, string, string, sysprop_src_dir, sysprop_src_excludes_pattern, sysprop_src_pattern, test, test, testsuite

The Groovy JavadocAssertionTestSuite.groovy source code

/*
 * Copyright 2003-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package groovy.util

import junit.framework.TestSuite
import junit.framework.Test
import junit.textui.TestRunner

/**
 * <code>JavadocAssertionTestSuite will dynamically create test cases from Groovy assertions placed within
 * Javadoc comments. Assertions should be placed within an html tag with a <code>class="groovyTestCase"
 * attribute assignment. Example:
 * <pre><pre class="groovyTestCase"> assert "example".size() == 7 </pre>
* * Source files will be read from the directory specified by the <code>javadocAssertion.src.dir * system property, including all files matching <code>javadocAssertion.src.pattern and * excluding files matching the <code>javadocAssertion.src.excludesPattern. * * By default all <code>.java and .groovy source files from ./src will * be scanned for assertions. * * You can also run this class as an application from the command line (assumes Groovy, JUnit and Ant * are on the classpath). As an example: * <p/> * <code> * java groovy.util.JavadocAssertionTestSuite src/main * </code> * * @author Merlyn Albery-Speyer */ class JavadocAssertionTestSuite extends TestSuite { /** The System Property to set as base directory for collection of Classes. * The pattern will be used as an Ant fileset include basedir. * Key is "javadocAssertion.src.dir". * Defaults to the <code>./src directory */ public static final String SYSPROP_SRC_DIR = "javadocAssertion.src.dir"; /** The System Property to set as the filename pattern for collection of Classes. * The pattern will be used as Regular Expression pattern applied with the find * operator against each candidate file.path. * Key is "javadocAssertion.src.pattern". * Defaults to including all <code>.java and .groovy files. */ public static final String SYSPROP_SRC_PATTERN = "javadocAssertion.src.pattern"; /** The System Property to set as a filename excludes pattern for collection of Classes. * When non-empty, the pattern will be used as Regular Expression pattern applied with the * find operator against each candidate file.path. * Key is "javadocAssertion.src.excludesPattern". * Default value is "". */ public static final String SYSPROP_SRC_EXCLUDES_PATTERN = "javadocAssertion.src.excludesPattern"; private static JavadocAssertionTestBuilder testBuilder = new JavadocAssertionTestBuilder() private static IFileNameFinder finder = new FileNameFinder() static Test suite() { String basedir = System.getProperty(SYSPROP_SRC_DIR, "./src/") return suite(basedir) } static Test suite(String basedir) { String includePattern = System.getProperty(SYSPROP_SRC_PATTERN, "**/*.java,**/*.groovy") return suite(basedir, includePattern) } static Test suite(String basedir, String includePattern) { String excludePattern = System.getProperty(SYSPROP_SRC_EXCLUDES_PATTERN, "") return suite(basedir, includePattern, excludePattern) } static Test suite(String basedir, String includePattern, String excludePattern) { assert new File(basedir).exists() TestSuite suite = new JavadocAssertionTestSuite() Collection filenames = finder.getFileNames([dir:basedir, includes:includePattern, excludes:excludePattern]) filenames.each { filename -> String code = new File(filename).text Class test = testBuilder.buildTest(filename, code) if (test != null) { suite.addTestSuite(test) } } return suite } static void main(String[] args) { switch(args.length) { case 3: TestRunner.run(suite(args[0], args[1], args[2])) break case 2: TestRunner.run(suite(args[0], args[1])) break case 1: TestRunner.run(suite(args[0])) break default: TestRunner.run(suite()) } } }

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy JavadocAssertionTestSuite.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.