KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > error > BaseErrorTestCase


1 // Copyright 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.error;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.IPage;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.error.TestExceptionPresenter.ExceptionFixture;
21 import org.apache.tapestry.services.ResponseRenderer;
22 import org.apache.tapestry.test.Creator;
23 import org.easymock.MockControl;
24
25 /**
26  * Base class for tests of the various error reporting service implementations.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public abstract class BaseErrorTestCase extends HiveMindTestCase
32 {
33
34     protected IPage newPage()
35     {
36         Creator c = new Creator();
37     
38         return (IPage) c.newInstance(ExceptionFixture.class);
39     }
40
41     protected IRequestCycle newCycle(String JavaDoc pageName, IPage page)
42     {
43         MockControl control = newControl(IRequestCycle.class);
44         IRequestCycle cycle = (IRequestCycle) control.getMock();
45     
46         cycle.getPage(pageName);
47         control.setReturnValue(page);
48     
49         return cycle;
50     }
51
52     protected ResponseRenderer newRenderer(IRequestCycle cycle, Throwable JavaDoc throwable) throws Exception JavaDoc
53     {
54         MockControl control = newControl(ResponseRenderer.class);
55         ResponseRenderer renderer = (ResponseRenderer) control.getMock();
56     
57         renderer.renderResponse(cycle);
58     
59         if (throwable != null)
60             control.setThrowable(throwable);
61     
62         return renderer;
63     }
64
65     protected RequestExceptionReporter newReporter()
66     {
67         return (RequestExceptionReporter) newMock(RequestExceptionReporter.class);
68     }
69
70 }
71
Popular Tags