KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > rules > TestIdTranslators


1 // Copyright 2004, 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 hivemind.test.rules;
16
17 import org.apache.hivemind.internal.Module;
18 import org.apache.hivemind.schema.Translator;
19 import org.apache.hivemind.schema.rules.IdListTranslator;
20 import org.apache.hivemind.schema.rules.QualifiedIdTranslator;
21 import org.apache.hivemind.test.HiveMindTestCase;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.hivemind.schema.rules.QualifiedIdTranslator}
26  * and {@link org.apache.hivemind.schema.rules.IdListTranslator}.
27  *
28  * @author Howard Lewis Ship
29  */

30 public class TestIdTranslators extends HiveMindTestCase
31 {
32     public void testNullId()
33     {
34         Translator t = new QualifiedIdTranslator();
35
36         assertNull(t.translate(null, null, null, null));
37     }
38
39     private Module getModule()
40     {
41         MockControl c = newControl(Module.class);
42         Module result = (Module) c.getMock();
43
44         result.getModuleId();
45         c.setReturnValue("foo.bar");
46
47         return result;
48     }
49
50     public void testNonNullId()
51     {
52         Module m = getModule();
53
54         replayControls();
55
56         Translator t = new QualifiedIdTranslator();
57
58         assertEquals("foo.bar.Baz", t.translate(m, null, "Baz", null));
59
60         verifyControls();
61     }
62
63     public void testNullList()
64     {
65         Translator t = new IdListTranslator();
66
67         assertEquals(null, t.translate(null, null, null, null));
68     }
69
70     public void testNonNullList()
71     {
72         Module m = getModule();
73
74         replayControls();
75
76         Translator t = new IdListTranslator();
77
78         assertEquals("foo.bar.Baz,zip.Zap", t.translate(m, null, "Baz,zip.Zap", null));
79
80         verifyControls();
81     }
82 }
83
Popular Tags