KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > enhance > TestEnhancedClassValidator


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.enhance;
16
17 import org.apache.hivemind.ErrorLog;
18 import org.apache.hivemind.Location;
19 import org.apache.hivemind.test.HiveMindTestCase;
20 import org.apache.tapestry.spec.IComponentSpecification;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.enhance.EnhancedClassValidatorImpl}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestEnhancedClassValidator extends HiveMindTestCase
30 {
31     public static abstract class AbstractBase
32     {
33         public abstract void foo();
34     }
35
36     public static abstract class Incomplete extends AbstractBase
37     {
38         public void bar()
39         {
40             //
41
}
42     }
43
44     public static class Complete extends AbstractBase
45     {
46         public void foo()
47         {
48             //
49
}
50     }
51
52     /**
53      * Test for a class that fulfills its requirements (by implementing all inherited abstract
54      * methods.
55      */

56
57     public void testComplete()
58     {
59         EnhancedClassValidator v = new EnhancedClassValidatorImpl();
60
61         v.validate(AbstractBase.class, Complete.class, null);
62     }
63
64     /**
65      * Pass in an abstract class (with enhancement, its possible that a supposedly concrete class
66      * may omit implementing an inherited abstract method, which is the whole point of the
67      * validator.
68      */

69
70     public void testIncomplete()
71     {
72         ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
73         Location l = fabricateLocation(11);
74
75         MockControl specControl = newControl(IComponentSpecification.class);
76         IComponentSpecification spec = (IComponentSpecification) specControl.getMock();
77
78         spec.getLocation();
79         specControl.setReturnValue(l);
80
81         log
82                 .error(
83                         "Method 'public abstract void org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase.foo()' (declared in class org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase) has no implementation in class org.apache.tapestry.enhance.TestEnhancedClassValidator$AbstractBase (or enhanced subclass org.apache.tapestry.enhance.TestEnhancedClassValidator$Incomplete).",
84                         l,
85                         null);
86
87         replayControls();
88
89         EnhancedClassValidatorImpl v = new EnhancedClassValidatorImpl();
90         v.setErrorLog(log);
91
92         v.validate(AbstractBase.class, Incomplete.class, spec);
93
94         verifyControls();
95     }
96
97     /**
98      * Ensures that the code works when passed java.lang.Object (which has different inheritance
99      * than other classes.
100      */

101
102     public void testObject()
103     {
104         EnhancedClassValidator v = new EnhancedClassValidatorImpl();
105
106         v.validate(Object JavaDoc.class, Object JavaDoc.class, null);
107     }
108 }
Popular Tags