KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > TestThreadLocale


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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 JavaDoc;
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 {
32     public void testThreadSpecific() throws Exception JavaDoc
33     {
34         final Registry r = RegistryBuilder.constructDefaultRegistry();
35
36         final ThreadLocale tl = (ThreadLocale) r.getService(ThreadLocale.class);
37
38         assertSame(r.getLocale(), tl.getLocale());
39
40         tl.setLocale(Locale.KOREAN);
41
42         assertSame(Locale.KOREAN, tl.getLocale());
43
44         Thread JavaDoc t = new Thread JavaDoc()
45         {
46             public void run()
47             {
48                 assertSame(r.getLocale(), tl.getLocale());
49             }
50         };
51
52         t.start();
53         t.join();
54     }
55
56     public void testResetOnThreadCleanup() throws Exception JavaDoc
57     {
58         Registry r = RegistryBuilder.constructDefaultRegistry();
59
60         ThreadLocale tl = (ThreadLocale) r.getService(ThreadLocale.class);
61
62         Locale JavaDoc start = r.getLocale();
63
64         assertSame(start, tl.getLocale());
65
66         tl.setLocale(Locale.CANADA_FRENCH);
67
68         r.cleanupThread();
69
70         assertSame(start, tl.getLocale());
71     }
72
73 }
Popular Tags