KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import api.cintoo.messages.context.Context;
23 import org.testng.annotations.*;
24 import org.testng.Assert;
25
26 public class TestIdContext {
27   private static Context ID1 = IdContext.id("ID1");
28   private static Context ID2 = IdContext.id("ID2");
29
30   @Test
31   public void testMatches() {
32     Assert.assertTrue(ID1.matches(ID1), "ID1 matches ID1");
33   }
34
35   @Test
36   public void testDoesNotMatch() {
37     Assert.assertFalse( (ID2.matches(ID1)), "ID2 does not match ID1");
38     Assert.assertFalse( (ID1.matches(ID2)), "ID1 does not match ID2");
39   }
40
41   @Test
42   public void testHash() {
43     Assert.assertTrue( ID2.hashCode() != ID1.hashCode(), "Hashcodes of ID1 and ID2 are different");
44   }
45
46
47   @Test
48   public void testIdWithBundleManager() {
49     DefaultBundleManager manager = new DefaultBundleManager(new DefaultContextCache());
50     manager.setBundle("testp1", ID1);
51     manager.setBundle("testp2", ID2);
52
53     Assert.assertEquals(manager.getBundle(ID1, new Locale JavaDoc("de", "de")).getString("testKey1"), "testValue1", "Manager returns correct bundle for ID1");
54     Assert.assertEquals(manager.getBundle(ID2, new Locale JavaDoc("de", "de")).getString("testKey2"), "testValue2", "Manager returns correct bundle for ID2");
55   }
56
57 }
58
Popular Tags