View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit;
21  
22  import org.apache.myfaces.tobago.component.UILabel;
23  import org.apache.myfaces.tobago.internal.config.AbstractTobagoTestBase;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  public class LabelWithAccessKeyUnitTest extends AbstractTobagoTestBase {
28  
29    @Test
30    public void testSimple() {
31      final UILabel component = new UILabel();
32      component.setValue("Save");
33      final LabelWithAccessKey label = new LabelWithAccessKey(component);
34      Assert.assertEquals("Save", label.getLabel());
35      Assert.assertEquals(-1, label.getPos());
36      Assert.assertEquals(null, label.getAccessKey());
37    }
38  
39    @Test
40    public void testUmlauts() {
41      // Umlauts are not supported as accessKey
42      final UILabel component = new UILabel();
43      component.setValue("Löschen");
44      final LabelWithAccessKey label = new LabelWithAccessKey(component);
45      Assert.assertEquals("Löschen", label.getLabel());
46      Assert.assertEquals(-1, label.getPos());
47      Assert.assertEquals(null, label.getAccessKey());
48    }
49  
50    @Test
51    public void testKey() {
52      final UILabel component = new UILabel();
53      component.setValue("Save");
54      component.setAccessKey('a');
55      final LabelWithAccessKey label = new LabelWithAccessKey(component);
56      Assert.assertEquals("Save", label.getLabel());
57      Assert.assertEquals(1, label.getPos());
58      Assert.assertEquals((Character) 'a', label.getAccessKey());
59    }
60  
61    @Test
62    public void testKeyWithWongCase() {
63      final UILabel component = new UILabel();
64      component.setValue("Save");
65      component.setAccessKey('A');
66      final LabelWithAccessKey label = new LabelWithAccessKey(component);
67      Assert.assertEquals("Save", label.getLabel());
68      Assert.assertEquals(1, label.getPos());
69      Assert.assertEquals((Character) 'a', label.getAccessKey());
70    }
71  
72    @Test
73    public void testNumberKey() {
74      final UILabel component = new UILabel();
75      component.setValue("Save");
76      component.setAccessKey('5');
77      final LabelWithAccessKey label = new LabelWithAccessKey(component);
78      Assert.assertEquals("Save", label.getLabel());
79      Assert.assertEquals(-1, label.getPos());
80      Assert.assertEquals((Character) '5', label.getAccessKey());
81    }
82  
83    @Test
84    public void testForbiddenKey() {
85      final UILabel component = new UILabel();
86      component.setValue("Save");
87      component.setAccessKey('#');
88      final LabelWithAccessKey label = new LabelWithAccessKey(component);
89      Assert.assertEquals("Save", label.getLabel());
90      Assert.assertEquals(-1, label.getPos());
91      Assert.assertEquals(null, label.getAccessKey());
92    }
93  
94    @Test
95    public void testForbiddenKey2() {
96      final UILabel component = new UILabel();
97      component.setValue("Save");
98      component.setAccessKey('á');
99      final LabelWithAccessKey label = new LabelWithAccessKey(component);
100     Assert.assertEquals("Save", label.getLabel());
101     Assert.assertEquals(-1, label.getPos());
102     Assert.assertEquals(null, label.getAccessKey());
103   }
104 
105   @Test
106   public void testForbiddenKey3() {
107     final UILabel component = new UILabel();
108     component.setValue("Save");
109     component.setAccessKey('ä');
110     final LabelWithAccessKey label = new LabelWithAccessKey(component);
111     Assert.assertEquals("Save", label.getLabel());
112     Assert.assertEquals(-1, label.getPos());
113     Assert.assertEquals(null, label.getAccessKey());
114   }
115 
116   @Test
117   public void testNull() {
118     final UILabel component = new UILabel();
119     final LabelWithAccessKey label = new LabelWithAccessKey(component);
120     Assert.assertEquals(null, label.getLabel());
121     Assert.assertEquals(-1, label.getPos());
122     Assert.assertEquals(null, label.getAccessKey());
123   }
124 }