Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/KeysTest.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
22
import static org.openqa.selenium.Keys.LEFT;
23
import static org.openqa.selenium.Keys.chord;
24
import static org.openqa.selenium.Keys.getKeyFromUnicode;
25
26
import org.junit.jupiter.api.Tag;
27
import org.junit.jupiter.api.Test;
28
29
@Tag("UnitTests")
30
class KeysTest {
31
32
@Test
33
void charAtPosition0ReturnsKeyCode() {
34
assertThat(Keys.LEFT.charAt(0)).isNotEqualTo(0);
35
}
36
37
@Test
38
void charAtOtherPositionReturnsZero() {
39
assertThat(Keys.LEFT.charAt(10)).isEqualTo((char) 0);
40
}
41
42
@Test
43
void lengthIsAlwaysOne() {
44
assertThat(LEFT.length()).isEqualTo(1);
45
}
46
47
@Test
48
void validSubSequence() {
49
assertThat(String.valueOf(LEFT)).isEqualTo(LEFT.subSequence(0, 1));
50
}
51
52
@Test
53
void invalidSubSequenceThrows() {
54
assertThatExceptionOfType(IndexOutOfBoundsException.class)
55
.isThrownBy(() -> LEFT.subSequence(-1, 10));
56
}
57
58
@Test
59
void buildChord() {
60
CharSequence[] sequences = {"foo", Keys.LEFT};
61
assertThat(chord(sequences)).isEqualTo("foo\uE012\uE000");
62
}
63
64
@Test
65
void keyForCharacterCode() {
66
Keys key = Keys.LEFT;
67
assertThat((CharSequence) getKeyFromUnicode(key.charAt(0))).isEqualTo(key);
68
}
69
}
70
71