KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cintoo > messages > context > TestPackageContext


1 /*
2  * Copyright 2006 cintoo, Berlin, Germany
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package cintoo.messages.context;
17
18 import cintoo.messages.bundle.DefaultBundleManager;
19
20 import java.util.Locale JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 import org.testng.annotations.*;
24 import org.testng.Assert;
25
26 public class TestPackageContext {
27
28   @Test
29   public void testWithClassAsContext() {
30     PackageContext c = new PackageContext(TestPackageContext.class);
31     Assert.assertEquals(c.getName(), "cintoo.messages.context", "Returns correct package for class");
32   }
33
34   @Test
35   public void testMatches() {
36     PackageContext c1 = PackageContext.string("com.test.");
37     PackageContext c2 = PackageContext.string("com.");
38
39     Assert.assertTrue(c2.matches(c1), "com. matches com.test. as context");
40   }
41
42   @Test
43   public void testDoesNotMatch() {
44     PackageContext c1 = PackageContext.string("com.");
45     PackageContext c2 = PackageContext.string("com.test.");
46
47     Assert.assertTrue(!(c2.matches(c1)), "com.test. does not match com. as context");
48   }
49
50   @Test
51   public void testEmptyMatchesAll() {
52     PackageContext c1 = PackageContext.string("com.test.");
53     PackageContext c2 = PackageContext.string("");
54
55     Assert.assertTrue(c2.matches(c1), "'' matches com.test. as context");
56   }
57
58
59   @Test
60   public void testContextWithSameLength() {
61     Locale JavaDoc de_locale = new Locale JavaDoc("de", "de");
62     DefaultBundleManager manager = new DefaultBundleManager(new DefaultContextCache());
63     manager.setBundle("testp1", PackageContext.string("t1"));
64     manager.setBundle("testp2", PackageContext.string("t2"));
65
66     ResourceBundle JavaDoc bundle = manager.getBundle(PackageContext.string("t1"), de_locale);
67     Assert.assertEquals(bundle.getString("testKey1"), "testValue1", "Returns correct bundle for context t1");
68
69     bundle = manager.getBundle(PackageContext.string("t2"), de_locale);
70     Assert.assertEquals(bundle.getString("testKey2"), "testValue2", "Returns correct bundle for context t2");
71   }
72
73 }
74
Popular Tags