01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.tapestry.internal;
16:
17: import java.util.Collections;
18: import java.util.Map;
19:
20: import org.apache.tapestry.OptionModel;
21: import org.testng.Assert;
22: import org.testng.annotations.Test;
23:
24: public class OptionModelImplTest extends Assert {
25: @Test
26: public void basics() {
27: OptionModel model = new OptionModelImpl("Label", false, this );
28:
29: assertEquals(model.getLabel(), "Label");
30: assertFalse(model.isDisabled());
31: assertSame(model.getValue(), this );
32: assertNull(model.getAttributes());
33:
34: model = new OptionModelImpl("Fred", true, "fred");
35:
36: assertEquals(model.getLabel(), "Fred");
37: assertTrue(model.isDisabled());
38:
39: assertEquals(model.toString(), "OptionModel[Fred fred]");
40: }
41:
42: @Test
43: public void attributes_as_extra_parameters() {
44: OptionModel model = new OptionModelImpl("Label", false, this ,
45: "fred", "flintstone", "barney", "rubble");
46:
47: Map<String, String> attributes = model.getAttributes();
48:
49: assertEquals(attributes.size(), 2);
50: assertEquals(attributes.get("fred"), "flintstone");
51: assertEquals(attributes.get("barney"), "rubble");
52: }
53:
54: @Test
55: public void attributes_as_map_are_retained() {
56: Map<String, String> attributes = Collections.emptyMap();
57:
58: OptionModel model = new OptionModelImpl("Label", false, this,
59: attributes);
60:
61: assertSame(model.getAttributes(), attributes);
62: }
63: }
|