package org.apache.maven.aspectj;

/* ====================================================================
 *   Copyright 2004 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 junit.framework.TestCase;

public class AspectTest extends TestCase
{

    private static final String EXCEPTION_MESSAGE = "test exception " +
    "voluntarily raised and that should be caught in the test case";

    public void testSourceIsCorrectlyWeaved()
    {
        String argfiles = System.getProperty("maven.aspectj.argfiles");
        Dummy dummy = new Dummy();
        try
        {
            dummy.someMethod();
            fail("The Aspect should have thrown an exception");
        } catch (Exception expected)
        {
            assertEquals(EXCEPTION_MESSAGE, expected.getMessage());
        }

        if (argfiles == null)
        {
            assertTrue(dummy.isAspectAWeaved());
            assertTrue(dummy.isAspectBWeaved());
        } else
        {
            assertTrue(dummy.isAspectAWeaved());
            assertFalse(dummy.isAspectBWeaved());
        }
    }

    public void testTestIsCorrectlyWeaved()
    {
        try
        {
            this.someMethod();
            fail("The Aspect should have thrown an exception");
        } catch (Exception expected)
        {
            assertEquals(EXCEPTION_MESSAGE, expected.getMessage());
        }
    }
    
    public void someMethod()
    {
    }
} 