o Fixed NPE

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@739544 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-01-31 11:05:17 +00:00
parent 2c0b8db8e5
commit dd0662ab6a
2 changed files with 41 additions and 25 deletions

View File

@ -67,13 +67,16 @@ public abstract class AbstractMavenIntegrationTestCase
private String matchPattern;
private static final String DEFAULT_MATCH_PATTERN = "(.*?)-(RC[0-9]+|SNAPSHOT|RC[0-9]+-SNAPSHOT)";
protected AbstractMavenIntegrationTestCase()
{
this.matchPattern = DEFAULT_MATCH_PATTERN;
}
protected AbstractMavenIntegrationTestCase( String versionRangeStr )
{
this( versionRangeStr, "(.*?)-(RC[0-9]+|SNAPSHOT|RC[0-9]+-SNAPSHOT)" );
this( versionRangeStr, DEFAULT_MATCH_PATTERN );
}
protected AbstractMavenIntegrationTestCase( String versionRangeStr, String matchPattern )
@ -237,7 +240,7 @@ protected File setupLocalRepo()
return localRepo;
}
protected ArtifactVersion removePattern( ArtifactVersion version )
ArtifactVersion removePattern( ArtifactVersion version )
{
String v = version.toString();

View File

@ -19,34 +19,47 @@
* under the License.
*/
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.it.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import junit.framework.TestCase;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
public class MavenIntegrationTestCaseTest
extends TestCase
{
public void testRemovePattern()
public void testRemovePatternForTestWithVersionRange()
{
AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase( "[2.0,)" ) {};
assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1" ) ).toString() );
assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-SNAPSHOT" ) ).toString() );
assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-RC1" ) ).toString() );
assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-RC1-SNAPSHOT" ) ).toString() );
assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10" ) ).toString() );
assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-SNAPSHOT" ) ).toString() );
assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-RC1" ) ).toString() );
assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-RC1-SNAPSHOT" ) ).toString() );
AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase( "[2.0,)" )
{
// test case with version range
};
testRemovePattern( test );
}
public void testRemovePatternForTestWithoutVersionRange()
{
AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase()
{
// test case without version range
};
testRemovePattern( test );
}
private static void testRemovePattern( AbstractMavenIntegrationTestCase test )
{
assertVersionEquals( "2.1.0-M1", "2.1.0-M1", test );
assertVersionEquals( "2.1.0-M1", "2.1.0-M1-SNAPSHOT", test );
assertVersionEquals( "2.1.0-M1", "2.1.0-M1-RC1", test );
assertVersionEquals( "2.1.0-M1", "2.1.0-M1-RC1-SNAPSHOT", test );
assertVersionEquals( "2.0.10", "2.0.10", test );
assertVersionEquals( "2.0.10", "2.0.10-SNAPSHOT", test );
assertVersionEquals( "2.0.10", "2.0.10-RC1", test );
assertVersionEquals( "2.0.10", "2.0.10-RC1-SNAPSHOT", test );
}
private static void assertVersionEquals( String expected, String version, AbstractMavenIntegrationTestCase test )
{
assertEquals( expected, test.removePattern( new DefaultArtifactVersion( version ) ).toString() );
}
}