01: // Copyright 2006, 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 java.util.Locale;
18:
19: import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
20: import org.apache.tapestry.ioc.services.ThreadLocale;
21: import org.testng.annotations.BeforeClass;
22: import org.testng.annotations.Test;
23:
24: public class ThreadLocaleImplTest extends IOCInternalTestCase {
25: private ThreadLocale _threadLocale;
26:
27: private static final Locale FAKE_LOCALE1 = new Locale("klingon");
28:
29: private static final Locale FAKE_LOCALE2 = new Locale("ferrengi");
30:
31: @BeforeClass
32: public void setup() {
33: _threadLocale = getService(ThreadLocale.class);
34: }
35:
36: @Test
37: public void different_threads_track_different_values()
38: throws InterruptedException {
39: final Locale initial = _threadLocale.getLocale();
40:
41: _threadLocale.setLocale(FAKE_LOCALE1);
42:
43: assertSame(_threadLocale.getLocale(), FAKE_LOCALE1);
44:
45: Runnable r = new Runnable() {
46: public void run() {
47: assertSame(_threadLocale.getLocale(), initial);
48: }
49: };
50:
51: Thread t = new Thread(r);
52:
53: t.start();
54: t.join();
55:
56: cleanupThread();
57: }
58:
59: public void thread_locale_reverts_after_cleanup() {
60: Locale initial = _threadLocale.getLocale();
61:
62: _threadLocale.setLocale(FAKE_LOCALE2);
63:
64: cleanupThread();
65:
66: assertSame(_threadLocale.getLocale(), initial);
67: }
68: }
|