001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.junit;
016    
017    import org.apache.hivemind.ApplicationRuntimeException;
018    import org.apache.tapestry.Tapestry;
019    import org.testng.annotations.Test;
020    
021    /**
022     * Tests for the methods
023     * {@link org.apache.tapestry.Tapestry#checkMethodInvocation(Object, String, Object)},
024     * {@link org.apache.tapestry.Tapestry#addMethodInvocation(Object)}and
025     * {@link org.apache.tapestry.Tapestry#clearMethodInvocations()}.
026     * 
027     * @author Howard Lewis Ship
028     * @since 3.0
029     */
030    @Test
031    public class TestTapestryCheckMethodInvocation extends TapestryTestCase
032    {
033    
034        public void testSuccess()
035        {
036            Tapestry.clearMethodInvocations();
037            Tapestry.addMethodInvocation("alpha");
038            Tapestry.addMethodInvocation("beta");
039    
040            Tapestry.checkMethodInvocation("alpha", "alpha()", this);
041            Tapestry.checkMethodInvocation("beta", "beta()", this);
042        }
043    
044        public void testFail()
045        {
046            Tapestry.clearMethodInvocations();
047    
048            try
049            {
050                Tapestry.checkMethodInvocation("gamma", "gamma()", this);
051                unreachable();
052            }
053            catch (ApplicationRuntimeException ex)
054            {
055                assertEquals(
056                        "Class org.apache.tapestry.junit.TestTapestryCheckMethodInvocation overrides method 'gamma()' but does not invoke the super-class implementation.",
057                        ex.getMessage());
058            }
059        }
060    
061    }