Path: blob/trunk/java/test/org/openqa/selenium/KeysTest.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.assertj.core.api.Assertions.assertThatExceptionOfType;21import static org.openqa.selenium.Keys.LEFT;22import static org.openqa.selenium.Keys.chord;23import static org.openqa.selenium.Keys.getKeyFromUnicode;2425import org.junit.jupiter.api.Tag;26import org.junit.jupiter.api.Test;2728@Tag("UnitTests")29class KeysTest {3031@Test32void charAtPosition0ReturnsKeyCode() {33assertThat(Keys.LEFT.charAt(0)).isNotEqualTo(0);34}3536@Test37void charAtOtherPositionReturnsZero() {38assertThat(Keys.LEFT.charAt(10)).isEqualTo((char) 0);39}4041@Test42void lengthIsAlwaysOne() {43assertThat(LEFT.length()).isEqualTo(1);44}4546@Test47void validSubSequence() {48assertThat(String.valueOf(LEFT)).isEqualTo(LEFT.subSequence(0, 1));49}5051@Test52void invalidSubSequenceThrows() {53assertThatExceptionOfType(IndexOutOfBoundsException.class)54.isThrownBy(() -> LEFT.subSequence(-1, 10));55}5657@Test58void buildChord() {59CharSequence[] sequences = {"foo", Keys.LEFT};60assertThat(chord(sequences)).isEqualTo("foo\uE012\uE000");61}6263@Test64void keyForCharacterCode() {65Keys key = Keys.LEFT;66assertThat((CharSequence) getKeyFromUnicode(key.charAt(0))).isEqualTo(key);67}68}697071