01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.internal.util;
16:
17: import org.apache.tapestry.internal.test.InternalBaseTestCase;
18: import org.apache.tapestry.runtime.Component;
19: import org.testng.annotations.Test;
20:
21: public class NotificationEventHandlerTest extends InternalBaseTestCase {
22: private static final String EVENT_TYPE = "myEventType";
23:
24: private static final String COMPLETE_ID = "foo.bar.baz";
25:
26: private static final String METHOD = "foo.components.Baz.bar()";
27:
28: @Test
29: public void true_is_allowed() {
30: Component component = mockComponent();
31:
32: replay();
33:
34: NotificationEventHandler handler = new NotificationEventHandler(
35: EVENT_TYPE, COMPLETE_ID);
36:
37: assertTrue(handler
38: .handleResult(Boolean.TRUE, component, METHOD));
39:
40: verify();
41: }
42:
43: @Test
44: public void false_is_allowed() {
45: Component component = mockComponent();
46:
47: replay();
48:
49: NotificationEventHandler handler = new NotificationEventHandler(
50: EVENT_TYPE, COMPLETE_ID);
51:
52: assertFalse(handler.handleResult(Boolean.FALSE, component,
53: METHOD));
54:
55: verify();
56: }
57:
58: @Test
59: public void other_values_force_exception() {
60: Component component = mockComponent();
61: String result = "*RESULT*";
62:
63: replay();
64:
65: NotificationEventHandler handler = new NotificationEventHandler(
66: EVENT_TYPE, COMPLETE_ID);
67:
68: try {
69: handler.handleResult(result, component, METHOD);
70: unreachable();
71: } catch (IllegalArgumentException ex) {
72: assertEquals(
73: ex.getMessage(),
74: "Event 'myEventType' from foo.bar.baz received an event handler method return value of *RESULT* from foo.components.Baz.bar(). "
75: + "This type of event does not support return values from event handler methods.");
76: }
77:
78: verify();
79: }
80:
81: }
|