mirror of https://github.com/apache/maven.git
o Added guard construct that marks a single test method as skipped (in contrast to matchesMavenVersion)
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@749623 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7ed71827d6
commit
4b386cdf97
|
@ -177,6 +177,12 @@ public abstract class AbstractMavenIntegrationTestCase
|
||||||
String result = "OK " + formatTime( milliseconds );
|
String result = "OK " + formatTime( milliseconds );
|
||||||
out.println( pad( RESULT_COLUMN - line.length() ) + result );
|
out.println( pad( RESULT_COLUMN - line.length() ) + result );
|
||||||
}
|
}
|
||||||
|
catch ( UnsupportedMavenVersionException e )
|
||||||
|
{
|
||||||
|
String result = "SKIPPED - version " + e.mavenVersion + " not in range " + e.supportedRange;
|
||||||
|
out.println( pad( RESULT_COLUMN - line.length() ) + result );
|
||||||
|
return;
|
||||||
|
}
|
||||||
catch ( Throwable t )
|
catch ( Throwable t )
|
||||||
{
|
{
|
||||||
milliseconds = System.currentTimeMillis() - milliseconds;
|
milliseconds = System.currentTimeMillis() - milliseconds;
|
||||||
|
@ -186,6 +192,57 @@ public abstract class AbstractMavenIntegrationTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guards the execution of a test case by checking that the current Maven version matches the specified version
|
||||||
|
* range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One
|
||||||
|
* would usually call this method right at the start of a test method.
|
||||||
|
*
|
||||||
|
* @param versionRange The version range that specifies the acceptable Maven versions for the test, must not be
|
||||||
|
* <code>null</code>.
|
||||||
|
*/
|
||||||
|
protected void requiresMavenVersion( String versionRange )
|
||||||
|
{
|
||||||
|
VersionRange range;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
range = VersionRange.createFromVersionSpec( versionRange );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRange ).initCause( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
ArtifactVersion version = getMavenVersion();
|
||||||
|
if ( version != null )
|
||||||
|
{
|
||||||
|
if ( !range.containsVersion( removePattern( version ) ) )
|
||||||
|
{
|
||||||
|
throw new UnsupportedMavenVersionException( version, range );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out.println( "WARNING: " + getITName() + ": version range '" + versionRange
|
||||||
|
+ "' supplied but no Maven version found - not skipping test." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class UnsupportedMavenVersionException
|
||||||
|
extends RuntimeException
|
||||||
|
{
|
||||||
|
|
||||||
|
public ArtifactVersion mavenVersion;
|
||||||
|
|
||||||
|
public VersionRange supportedRange;
|
||||||
|
|
||||||
|
public UnsupportedMavenVersionException( ArtifactVersion mavenVersion, VersionRange supportedRange )
|
||||||
|
{
|
||||||
|
this.mavenVersion = mavenVersion;
|
||||||
|
this.supportedRange = supportedRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private String getITName()
|
private String getITName()
|
||||||
{
|
{
|
||||||
String simpleName = getClass().getName();
|
String simpleName = getClass().getName();
|
||||||
|
|
|
@ -49,4 +49,25 @@ public class MavenIntegrationTestCaseTest
|
||||||
assertEquals( expected, test.removePattern( new DefaultArtifactVersion( version ) ).toString() );
|
assertEquals( expected, test.removePattern( new DefaultArtifactVersion( version ) ).toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRequiresMavenVersion()
|
||||||
|
{
|
||||||
|
System.setProperty( "maven.version", "2.1" );
|
||||||
|
|
||||||
|
AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase( "[2.0,)" )
|
||||||
|
{
|
||||||
|
// test case with version range
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
test.requiresMavenVersion( "[3.0,)" );
|
||||||
|
}
|
||||||
|
catch ( RuntimeException e )
|
||||||
|
{
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
test.requiresMavenVersion( "[2.0,)" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue