Changes

Jump to: navigation, search

Template Method

804 bytes removed, 17:41, 19 March 2007
Apache Excalibur
=== Apache Excalibur===
The following examples shows that class are portions of the code found in '''CascadingErrorTestCase.java''' is extending from an abstract class called and '''TestCaseCascadingExceptionTestCase.java'''files.<br/>When comparing these two files, possibly in we can see that the two files share a common package '''junitorg.apache.avalon.framework.TestCasetest''' package. In this case, the '''testConstructor()''' and the '''testGetCause()''' would be the altered for testing purposes. 
<pre>
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.avalon.framework.test;
import junit.framework.TestCase;
</**pre>  * From the following, we can see that the class '''CascadingErrorTestCase''' is extending from an abstract class called '''TestCase'''. This is the same case in the '''CascadingExceptionTestCase.java''' file. Hence, this shows that these two classes are subclasses of the class '''TestCase for {@link CascadingError}'''. * * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</apre> * @version $Id$ */
public class CascadingErrorTestCase extends TestCase
{
}
</pre>
 
When looking at the testConstructor() in both files, we can see that it implements different methods, therefore its altering the algorithm operation of the file. The general steps in the constructor is not altered, but the implementation is different.
<pre>
// From CascadingErrorTestCase.java
public void testConstructor()
{
//assertNotNull( new CascadingError() );
}
</pre> public void testGetCause()<pre>
{
RuntimeException re = assertNotNull( new RuntimeExceptionCascadingException(null, null ) ); CascadingError e = assertNotNull( new CascadingErrorCascadingException( "msg", re null ) );  assertEqualsassertNotNull( re, e.getCause() );  e = new CascadingErrorCascadingException( "msg", null new RuntimeException(); assertNull( e.getCause() );  // default to jdk 1.3 cause assertNotNull(not that it seems to help, // but it still makes sense) /*Exception exc = new ExceptionCascadingException("blah"); try { try { throw exc; } catch( Exception ex ) { throw null, new CascadingErrorRuntimeException(); } } catch( CascadingError ex ) { ex.getCause(); }*/ }
public void testCasts assertNotNull() { CascadingError e = new CascadingErrorCascadingException( "msg", null ) ); assertTrue// ambiguous assertNotNull( new CascadingException( e instanceof Error null ) ); assertTrue//assertNotNull( e instanceof CascadingThrowable new CascadingException() );
}
 
}
</pre>
1
edit

Navigation menu