001    package org.apache.maven.rtinfo.internal;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.rtinfo.RuntimeInformation;
023    import org.codehaus.plexus.PlexusTestCase;
024    
025    public class DefaultRuntimeInformationTest
026        extends PlexusTestCase
027    {
028    
029        public void testGetMavenVersion()
030            throws Exception
031        {
032            RuntimeInformation rtInfo = lookup( RuntimeInformation.class );
033    
034            String mavenVersion = rtInfo.getMavenVersion();
035            assertNotNull( mavenVersion );
036            assertTrue( mavenVersion.length() > 0 );
037        }
038    
039        public void testIsMavenVersion()
040            throws Exception
041        {
042            RuntimeInformation rtInfo = lookup( RuntimeInformation.class );
043    
044            assertTrue( rtInfo.isMavenVersion( "2.0" ) );
045            assertFalse( rtInfo.isMavenVersion( "9.9" ) );
046    
047            assertTrue( rtInfo.isMavenVersion( "[2.0.11,2.1.0),[3.0,)" ) );
048            assertFalse( rtInfo.isMavenVersion( "[9.0,)" ) );
049    
050            try
051            {
052                rtInfo.isMavenVersion( "[3.0," );
053                fail( "Bad version range wasn't rejected" );
054            }
055            catch ( IllegalArgumentException e )
056            {
057                assertTrue( true );
058            }
059    
060            try
061            {
062                rtInfo.isMavenVersion( "" );
063                fail( "Bad version range wasn't rejected" );
064            }
065            catch ( IllegalArgumentException e )
066            {
067                assertTrue( true );
068            }
069    
070            try
071            {
072                rtInfo.isMavenVersion( null );
073                fail( "Bad version range wasn't rejected" );
074            }
075            catch ( IllegalArgumentException e )
076            {
077                assertTrue( true );
078            }
079        }
080    
081    }