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 java.util.Collections;
18: import java.util.Map;
19:
20: import org.apache.tapestry.Translator;
21: import org.apache.tapestry.internal.test.InternalBaseTestCase;
22: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
23: import org.apache.tapestry.services.TranslatorSource;
24: import org.testng.annotations.Test;
25:
26: public class TranslatorSourceImplTest extends InternalBaseTestCase {
27: @Test
28: public void found_translator_by_name() {
29: Translator translator = mockTranslator();
30:
31: Map<String, Translator> configuration = Collections
32: .singletonMap("mock", translator);
33:
34: replay();
35:
36: TranslatorSource source = new TranslatorSourceImpl(
37: configuration);
38:
39: assertSame(source.get("mock"), translator);
40:
41: verify();
42: }
43:
44: @Test
45: public void unknown_translator_is_failure() {
46: Translator fred = mockTranslator();
47: Translator barney = mockTranslator();
48:
49: Map<String, Translator> configuration = CollectionFactory
50: .newMap();
51:
52: configuration.put("fred", fred);
53: configuration.put("barney", barney);
54:
55: replay();
56:
57: TranslatorSource source = new TranslatorSourceImpl(
58: configuration);
59:
60: try {
61: source.get("wilma");
62: unreachable();
63: } catch (RuntimeException ex) {
64: assertEquals(ex.getMessage(),
65: "Unknown translator type 'wilma'. Configured translators are barney, fred.");
66: }
67:
68: }
69: }
|