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.services;
16:
17: import org.apache.tapestry.annotations.Service;
18: import org.apache.tapestry.ioc.AnnotationProvider;
19: import org.apache.tapestry.ioc.ObjectLocator;
20: import org.apache.tapestry.ioc.ObjectProvider;
21: import org.apache.tapestry.test.TapestryTestCase;
22: import org.testng.annotations.Test;
23:
24: public class ServiceAnnotationObjectProviderTest extends
25: TapestryTestCase {
26: @SuppressWarnings("unchecked")
27: @Test
28: public void no_annotation() {
29: Class objectType = Runnable.class;
30: AnnotationProvider provider = mockAnnotationProvider();
31: ObjectLocator locator = mockObjectLocator();
32:
33: train_getAnnotation(provider, Service.class, null);
34:
35: replay();
36:
37: ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
38:
39: assertNull(objectProvider
40: .provide(objectType, provider, locator));
41:
42: verify();
43: }
44:
45: @SuppressWarnings("unchecked")
46: @Test
47: public void annotation_present() {
48: Class objectType = Runnable.class;
49: AnnotationProvider provider = mockAnnotationProvider();
50: ObjectLocator locator = mockObjectLocator();
51: Service service = newMock(Service.class);
52: String serviceId = "JiffyPop";
53: Runnable instance = mockRunnable();
54:
55: train_getAnnotation(provider, Service.class, service);
56:
57: expect(service.value()).andReturn(serviceId);
58:
59: train_getService(locator, serviceId, objectType, instance);
60:
61: replay();
62:
63: ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
64:
65: assertSame(objectProvider
66: .provide(objectType, provider, locator), instance);
67:
68: verify();
69: }
70: }
|