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.ObjectProvider;
20: import org.apache.tapestry.ioc.annotations.Symbol;
21: import org.apache.tapestry.ioc.services.SymbolSource;
22: import org.apache.tapestry.ioc.services.TypeCoercer;
23: import org.apache.tapestry.ioc.test.IOCTestCase;
24: import org.testng.annotations.Test;
25:
26: public class SymbolObjectProviderTest extends IOCTestCase {
27: @Test
28: public void no_annotation() {
29: SymbolSource source = mockSymbolSource();
30: TypeCoercer coercer = mockTypeCoercer();
31: AnnotationProvider annotationProvider = mockAnnotationProvider();
32: ObjectLocator locator = mockObjectLocator();
33:
34: train_getAnnotation(annotationProvider, Symbol.class, null);
35:
36: replay();
37:
38: ObjectProvider provider = new SymbolObjectProvider(source,
39: coercer);
40:
41: assertNull(provider.provide(Long.class, annotationProvider,
42: locator));
43:
44: verify();
45: }
46:
47: @Test
48: public void annotation_present() {
49: SymbolSource source = mockSymbolSource();
50: TypeCoercer coercer = mockTypeCoercer();
51: AnnotationProvider annotationProvider = mockAnnotationProvider();
52: ObjectLocator locator = mockObjectLocator();
53: Symbol annotation = newMock(Symbol.class);
54: String symbolName = "example-symbol";
55: String symbolValue = "symbol-value";
56: Long coercedValue = 123l;
57:
58: train_getAnnotation(annotationProvider, Symbol.class,
59: annotation);
60:
61: expect(annotation.value()).andReturn(symbolName);
62:
63: train_valueForSymbol(source, symbolName, symbolValue);
64:
65: train_coerce(coercer, symbolValue, Long.class, coercedValue);
66:
67: replay();
68:
69: ObjectProvider provider = new SymbolObjectProvider(source,
70: coercer);
71:
72: assertSame(provider.provide(Long.class, annotationProvider,
73: locator), coercedValue);
74:
75: verify();
76: }
77:
78: protected final void train_valueForSymbol(SymbolSource source,
79: String symbolName, String symbolValue) {
80: expect(source.valueForSymbol(symbolName))
81: .andReturn(symbolValue);
82: }
83: }
|