01: // Copyright 2006 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.io.IOException;
18: import java.util.Locale;
19: import java.util.Map;
20:
21: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
22: import org.apache.tapestry.services.Cookies;
23: import org.apache.tapestry.services.PersistentLocale;
24: import org.apache.tapestry.services.PersistentLocaleImpl;
25: import org.testng.Assert;
26: import org.testng.annotations.Test;
27:
28: public class PersistentLocaleImplTest extends Assert {
29: @Test
30: public void get() throws IOException {
31: Cookies cookieSource = new NoOpCookieSource() {
32:
33: @Override
34: public String readCookieValue(String name) {
35: return name.equals("org.apache.tapestry.locale") ? "fr"
36: : null;
37: }
38:
39: };
40: PersistentLocale persistentLocale = new PersistentLocaleImpl(
41: cookieSource);
42: assertEquals(persistentLocale.get(), Locale.FRENCH);
43: }
44:
45: @Test
46: public void get_none() throws IOException {
47: Cookies cookieSource = new NoOpCookieSource() {
48:
49: @Override
50: public String readCookieValue(String name) {
51: return null;
52: }
53:
54: };
55: PersistentLocale persistentLocale = new PersistentLocaleImpl(
56: cookieSource);
57: assertNull(persistentLocale.get());
58: }
59:
60: @Test
61: public void set() throws IOException {
62: final Map<String, String> cookies = CollectionFactory.newMap();
63: Cookies cookieSource = new NoOpCookieSource() {
64: @Override
65: public void writeCookieValue(String name, String value) {
66: cookies.put(name, value);
67: }
68:
69: };
70: PersistentLocale persistentLocale = new PersistentLocaleImpl(
71: cookieSource);
72: persistentLocale.set(Locale.CANADA_FRENCH);
73: assertEquals(cookies.size(), 1);
74: assertEquals(cookies.get("org.apache.tapestry.locale"), "fr_CA");
75: }
76:
77: }
|