-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved handling of special chars typed on varying locales on assist…
…ant/assisted should close #28
- Loading branch information
Showing
3 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/test/java/mpo/dayon/assisted/control/RobotNetworkControlMessageHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package mpo.dayon.assisted.control; | ||
|
||
import mpo.dayon.common.network.message.NetworkKeyControlMessage; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
|
||
import java.awt.*; | ||
import java.awt.event.KeyEvent; | ||
|
||
import static mpo.dayon.common.network.message.NetworkKeyControlMessage.KeyState.PRESSED; | ||
import static mpo.dayon.common.network.message.NetworkKeyControlMessage.KeyState.RELEASED; | ||
import static org.junit.jupiter.api.condition.OS.WINDOWS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class RobotNetworkControlMessageHandlerTest { | ||
|
||
Robot robot = mock(Robot.class); | ||
RobotNetworkControlMessageHandler controlMessageHandler = new RobotNetworkControlMessageHandler(robot); | ||
|
||
@Test | ||
void testHandleMessagePressA() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(PRESSED, 65, 'A'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
verify(robot).keyPress(message.getKeyChar()); | ||
} | ||
|
||
@Test | ||
void testHandleMessageReleaseA() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(RELEASED, 65, 'A'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
verify(robot).keyRelease(message.getKeyChar()); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(WINDOWS) | ||
void testHandleMessagePressTurkishLowerSpecialSTypedOnNonTurkishAssisted() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(PRESSED, 0, 'ş'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
verify(robot).keyPress(KeyEvent.VK_CONTROL); | ||
verify(robot).keyPress(KeyEvent.VK_SHIFT); | ||
verify(robot).keyPress(KeyEvent.VK_U); | ||
verify(robot).keyRelease(KeyEvent.VK_U); | ||
// 351 as hex 15F | ||
verify(robot).keyPress(KeyEvent.VK_1); | ||
verify(robot).keyRelease(KeyEvent.VK_1); | ||
verify(robot).keyPress(KeyEvent.VK_5); | ||
verify(robot).keyRelease(KeyEvent.VK_5); | ||
verify(robot).keyPress(KeyEvent.VK_F); | ||
verify(robot).keyRelease(KeyEvent.VK_F); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(WINDOWS) | ||
void testHandleMessageReleaseTurkishLowerSpecialSTypedOnNonTurkishAssisted() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(RELEASED, 0, 'ş'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
robot.keyRelease(KeyEvent.VK_SHIFT); | ||
robot.keyRelease(KeyEvent.VK_CONTROL); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(WINDOWS) | ||
void testHandleMessagePressTurkishUpperSpecialSTypedOnNonTurkishAssisted() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(PRESSED, 0, 'Ş'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
verify(robot).keyPress(KeyEvent.VK_CONTROL); | ||
verify(robot).keyPress(KeyEvent.VK_SHIFT); | ||
verify(robot).keyPress(KeyEvent.VK_U); | ||
verify(robot).keyRelease(KeyEvent.VK_U); | ||
// 350 as hex 15E | ||
verify(robot).keyPress(KeyEvent.VK_1); | ||
verify(robot).keyRelease(KeyEvent.VK_1); | ||
verify(robot).keyPress(KeyEvent.VK_5); | ||
verify(robot).keyRelease(KeyEvent.VK_5); | ||
verify(robot).keyPress(KeyEvent.VK_E); | ||
verify(robot).keyRelease(KeyEvent.VK_E); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(WINDOWS) | ||
void testHandleMessageReleaseTurkishUpperSpecialSTypedOnNonTurkishAssisted() { | ||
// given | ||
NetworkKeyControlMessage message = new NetworkKeyControlMessage(RELEASED, 0, 'Ş'); | ||
// when | ||
controlMessageHandler.handleMessage(message); | ||
// then | ||
robot.keyRelease(KeyEvent.VK_SHIFT); | ||
robot.keyRelease(KeyEvent.VK_CONTROL); | ||
} | ||
} |