KickJava   Java API By Example, From Geeks To Geeks.

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


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 hivemind.test.FrameworkTestCase;
18
19 import java.util.Map JavaDoc;
20
21 import org.apache.hivemind.ApplicationRuntimeException;
22 import org.apache.hivemind.schema.rules.RuleUtils;
23
24 /**
25  * Tests for {@link RuleUtils#convertInitializer(String)}.
26  *
27  * @author Howard Lewis Ship
28  */

29 public class TestConvertInitializer extends FrameworkTestCase
30 {
31
32     public void testEmpty()
33     {
34         Map JavaDoc m = RuleUtils.convertInitializer(null);
35
36         assertEquals(true, m.isEmpty());
37
38         m = RuleUtils.convertInitializer("");
39
40         assertEquals(true, m.isEmpty());
41     }
42
43     public void testSimple()
44     {
45         Map JavaDoc m = RuleUtils.convertInitializer("alpha=bravo");
46
47         assertEquals(1, m.size());
48         assertEquals("bravo", m.get("alpha"));
49     }
50
51     public void testComplex()
52     {
53         Map JavaDoc m = RuleUtils.convertInitializer("alpha=bravo,fred=barney,gromit=greyhound");
54
55         assertEquals(3, m.size());
56         assertEquals("bravo", m.get("alpha"));
57         assertEquals("barney", m.get("fred"));
58         assertEquals("greyhound", m.get("gromit"));
59     }
60
61     public void testFailure()
62     {
63         try
64         {
65             RuleUtils.convertInitializer("bad");
66
67             unreachable();
68         }
69         catch (ApplicationRuntimeException ex)
70         {
71             assertExceptionSubstring(
72                 ex,
73                 "Initializer string ('bad') is not in proper format (key=value[,key=value]*).");
74         }
75     }
76 }
77
Popular Tags