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.ioc.internal.services;
16:
17: import org.apache.tapestry.ioc.AnnotationProvider;
18: import org.apache.tapestry.ioc.ObjectLocator;
19: import org.apache.tapestry.ioc.annotations.Value;
20: import org.apache.tapestry.ioc.services.SymbolSource;
21: import org.apache.tapestry.ioc.services.TypeCoercer;
22: import org.apache.tapestry.ioc.test.IOCTestCase;
23: import org.testng.annotations.Test;
24:
25: public class ValueObjectProviderTest extends IOCTestCase {
26: @Test
27: public void no_value_annotation() {
28: SymbolSource symbolSource = mockSymbolSource();
29: TypeCoercer coercer = mockTypeCoercer();
30: AnnotationProvider annotationProvider = mockAnnotationProvider();
31: ObjectLocator locator = mockObjectLocator();
32:
33: train_getAnnotation(annotationProvider, Value.class, null);
34:
35: replay();
36:
37: ValueObjectProvider provider = new ValueObjectProvider(
38: symbolSource, coercer);
39:
40: assertNull(provider.provide(Runnable.class, annotationProvider,
41: locator));
42:
43: verify();
44: }
45:
46: @Test
47: public void value_annotation_present() {
48: SymbolSource symbolSource = mockSymbolSource();
49: TypeCoercer coercer = mockTypeCoercer();
50: AnnotationProvider annotationProvider = mockAnnotationProvider();
51: ObjectLocator locator = mockObjectLocator();
52: String annotationValue = "${foo}";
53: String expanded = "Foo";
54: Runnable coerced = mockRunnable();
55: Value annotation = newMock(Value.class);
56:
57: train_getAnnotation(annotationProvider, Value.class, annotation);
58:
59: expect(annotation.value()).andReturn(annotationValue);
60:
61: train_expandSymbols(symbolSource, annotationValue, expanded);
62: train_coerce(coercer, expanded, Runnable.class, coerced);
63:
64: replay();
65:
66: ValueObjectProvider provider = new ValueObjectProvider(
67: symbolSource, coercer);
68:
69: assertSame(provider.provide(Runnable.class, annotationProvider,
70: locator), coerced);
71:
72: verify();
73: }
74: }
|