abstractcoberturatestcase.java

来自「anewssystem新闻发布系统集成使用了spring hibernate f」· Java 代码 · 共 138 行

JAVA
138
字号
package org.codehaus.mojo.cobertura;

/*
 * Copyright 2001-2006 The Apache Software Foundation.
 *
 * 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.
 */

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.mojo.cobertura.stubs.ArtifactStub;
import org.codehaus.plexus.PlexusTestCase;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Base TestCase for all Cobertura Tests.
 * 
 * @author Joakim Erdfelt
 */
public abstract class AbstractCoberturaTestCase
    extends AbstractMojoTestCase
{
    protected void assertArtifactExists( Artifact artifact )
    {
        if ( artifact == null )
        {
            fail( "Artifact is null." );
        }

        if ( artifact.getFile() == null )
        {
            fail( "Artifact.file is not defined for " + artifact );
        }

        if ( !artifact.getFile().exists() )
        {
            fail( "Artifact " + artifact.getFile().getAbsolutePath() + " file does not exist." );
        }
    }

    protected List getPluginClasspath()
        throws Exception
    {
        String localRepository = System.getProperty( "localRepository" );
        
        assertNotNull( "System.property(localRepository) should not be null.", localRepository );

        List pluginClasspath = new ArrayList();

        Artifact artifact;

//        artifact = new ArtifactStub();
//        artifact.setFile( new File( PlexusTestCase.getBasedir() + "/target/classes" ) );
//        assertArtifactExists( artifact );
//        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "net.sourceforge.cobertura" );
        artifact.setArtifactId( "cobertura" );
        artifact.setVersion( "1.9" );
        artifact.setFile( new File( localRepository + "/net/sourceforge/cobertura/cobertura/1.9/cobertura-1.9.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "log4j" );
        artifact.setArtifactId( "log4j" );
        artifact.setVersion( "1.2.9" );
        artifact.setFile( new File( localRepository + "/log4j/log4j/1.2.9/log4j-1.2.9.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "org.apache.ant" );
        artifact.setArtifactId( "ant" );
        artifact.setVersion( "1.7.0" );
        artifact.setFile( new File( localRepository + "/org/apache/ant/ant/1.7.0/ant-1.7.0.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "org.apache.ant" );
        artifact.setArtifactId( "ant-launcher" );
        artifact.setVersion( "1.7.0" );
        artifact.setFile( new File( localRepository + "/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "oro" );
        artifact.setArtifactId( "oro" );
        artifact.setVersion( "2.0.8" );
        artifact.setFile( new File( localRepository + "/oro/oro/2.0.8/oro-2.0.8.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "asm" );
        artifact.setArtifactId( "asm" );
        artifact.setVersion( "2.2.1" );
        artifact.setFile( new File( localRepository + "/asm/asm/2.2.1/asm-2.2.1.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "asm" );
        artifact.setArtifactId( "asm-tree" );
        artifact.setVersion( "2.2.1" );
        artifact.setFile( new File( localRepository + "/asm/asm-tree/2.2.1/asm-tree-2.2.1.jar" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        artifact = new ArtifactStub();
        artifact.setGroupId( "net.sourceforge.cobertura" );
        artifact.setArtifactId( "cobertura-runtime" );
        artifact.setVersion( "1.8" );
        artifact.setFile( new File( localRepository + "/net/sourceforge/cobertura/cobertura-runtime/1.9/cobertura-runtime-1.9.pom" ) );
        assertArtifactExists( artifact );
        pluginClasspath.add( artifact );

        return pluginClasspath;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?