coberturacheckmojotest.java

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

JAVA
175
字号
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.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.PlexusTestCase;

import java.io.File;

/**
 * @author Edwin Punzalan
 */
public class CoberturaCheckMojoTest
    extends AbstractCoberturaTestCase
{
    public void testMojo()
        throws Exception
    {
        try {
            Mojo mojo = lookupMojo( "check",
                                    PlexusTestCase.getBasedir() + "/src/test/plugin-configs/check-plugin-config.xml" );

            setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

            mojo.execute();
        } catch (Exception ex) {
        }
    }

    public void testCheckWithRegexPassing()
        throws Exception
    {
        try {
            Mojo mojo = lookupMojo( "check", PlexusTestCase.getBasedir() +
                                    "/src/test/plugin-configs/check-regex-pass-plugin-config.xml" );

            setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

            mojo.execute();
        } catch (Exception ex) {
        }
    }

    public void testCheckWithRegexFailing()
        throws Exception
    {
        Mojo mojo = lookupMojo( "check", PlexusTestCase.getBasedir() +
                                "/src/test/plugin-configs/check-regex-fail-plugin-config.xml" );

        setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

        try
        {
            mojo.execute();

            fail( "regex should fail at < 100% coverage" );
        }
        catch ( MojoExecutionException e )
        {
            if ( !e.getMessage().equals( "Coverage check failed. See messages above." ) )
            {
                fail( "Unexpected exception thrown" );
            }
        }
    }

    public void testCheckFailure()
        throws Exception
    {
        Mojo mojo = lookupMojo( "check",
                                PlexusTestCase.getBasedir() + "/src/test/plugin-configs/check-halt-plugin-config.xml" );

        setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

        try
        {
            mojo.execute();

            fail( "Should fail when rates are not satisfied" );
        }
        catch ( MojoExecutionException e )
        {
            if ( !e.getMessage().equals( "Coverage check failed. See messages above." ) )
            {
                fail( "Unexpected exception thrown" );
            }
        }
    }

    public void testCheckFailureNoHalt()
        throws Exception
    {
        Mojo mojo = lookupMojo( "check",
                                PlexusTestCase.getBasedir() + "/src/test/plugin-configs/check-no-halt-plugin-config.xml" );

        setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

        try
        {
            mojo.execute();
        }
        catch ( MojoExecutionException e )
        {
            if ( e.getMessage().equals( "Coverage check failed. See messages above." ) )
            {
                fail( "Should fail when rates are not satisfied" );
            }
            else
            {
                fail( "Unexpected exception" );
            }
        }
    }

    public void testNoCheckParameter()
        throws Exception
    {
        Mojo mojo = lookupMojo( "check",
                                PlexusTestCase.getBasedir() + "/src/test/plugin-configs/check-plugin-config.xml" );

        setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

        setVariableValueToObject( mojo, "check", null );

        try
        {
            mojo.execute();

            fail( "Should fail on null check parameter" );
        }
        catch ( MojoExecutionException e )
        {
            if ( !e.getMessage().equals( "The Check configuration is missing." ) )
            {
                fail( "Unexpected exception" );
            }
        }
    }

    public void testNoDataFileParameter()
        throws Exception
    {
        Mojo mojo = lookupMojo( "check",
                                PlexusTestCase.getBasedir() + "/src/test/plugin-configs/check-plugin-config.xml" );

        setVariableValueToObject( mojo, "pluginClasspathList", getPluginClasspath() );

        setVariableValueToObject( mojo, "dataFile", new File( PlexusTestCase.getBasedir() + "/no/such/file" ) );

        try
        {
            mojo.execute();
        }
        catch ( MojoExecutionException e )
        {
            fail( "Should not fail" );
        }
    }
}

⌨️ 快捷键说明

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