01: // Copyright 2005 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.hivemind;
16:
17: import java.util.Locale;
18:
19: import org.apache.hivemind.impl.RegistryBuilder;
20: import org.apache.hivemind.service.ThreadLocale;
21: import org.apache.hivemind.test.HiveMindTestCase;
22:
23: /**
24: * Tests for {@link org.apache.hivemind.service.ThreadLocale} service. We revert to using
25: * integration tests because unit tests would not be very meaningful.
26: *
27: * @author Howard M. Lewis Ship
28: * @since 1.1
29: */
30: public class TestThreadLocale extends HiveMindTestCase {
31: public void testThreadSpecific() throws Exception {
32: final Registry r = RegistryBuilder.constructDefaultRegistry();
33:
34: final ThreadLocale tl = (ThreadLocale) r
35: .getService(ThreadLocale.class);
36:
37: assertSame(r.getLocale(), tl.getLocale());
38:
39: tl.setLocale(Locale.KOREAN);
40:
41: assertSame(Locale.KOREAN, tl.getLocale());
42:
43: Thread t = new Thread() {
44: public void run() {
45: assertSame(r.getLocale(), tl.getLocale());
46: }
47: };
48:
49: t.start();
50: t.join();
51: }
52:
53: public void testResetOnThreadCleanup() throws Exception {
54: Registry r = RegistryBuilder.constructDefaultRegistry();
55:
56: ThreadLocale tl = (ThreadLocale) r
57: .getService(ThreadLocale.class);
58:
59: Locale start = r.getLocale();
60:
61: assertSame(start, tl.getLocale());
62:
63: tl.setLocale(Locale.CANADA_FRENCH);
64:
65: r.cleanupThread();
66:
67: assertSame(start, tl.getLocale());
68: }
69:
70: }
|