package pl.mkrystek.mkbot.pl.mkrystek.mkbot;

import static org.mockito.Mockito.inOrder;
import static java.awt.event.KeyEvent.*;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import java.awt.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class KeyboardTest {

    @Mock
    private Robot robot;

    @InjectMocks
    private Keyboard keyboard;

    InOrder order;

    @Before
    public void setUp() {
        order = inOrder(robot);
    }

    @Test
    public void shouldPressProperKeys() {
        //given
        String sampleMessage = "AbC";

        //when
        keyboard.type(sampleMessage);

        //then
        verifySequencePressed(VK_SHIFT, VK_A);
        verifySequencePressed(VK_B);
        verifySequencePressed(VK_SHIFT, VK_C);
        verifyNoMoreInteractions(robot);
    }

    private void verifySequencePressed(int... sequence) {
        verifySequence(sequence);
    }

    private void verifySequence(int... keyCodes) {
        verifySequence(keyCodes, 0, keyCodes.length);
    }

    private void verifySequence(int[] keyCodes, int offset, int length) {
        if (length == 0) {
            return;
        }

        order.verify(robot).keyPress(keyCodes[offset]);
        verifySequence(keyCodes, offset + 1, length - 1);
        order.verify(robot).keyRelease(keyCodes[offset]);
    }
}
@@ -694,28 +694,29 @@
 oid 
-shouldPressProperKey
+testTypingSmallLetter
 s() 
@@ -752,28 +752,61 @@
 ing 
-sampleMessage = %22AbC
+messageWithSmallLetters = %22abcdefghijklmnopqrstuvwxyz
 %22;%0A%0A
@@ -846,21 +846,31 @@
 ype(
-sampleMessage
+messageWithSmallLetters
 );%0A%0A
@@ -896,268 +896,1202 @@
     
-verifySequencePressed(VK_SHIFT, VK_A);%0A        verifySequencePressed(VK_B);%0A        verifySequencePressed(VK_SHIFT, VK_C);%0A        verifyNoMoreInteractions(robot);%0A    %7D%0A%0A    private void verifySequencePressed(int... sequence) %7B%0A        verifySequence(sequence
+for (int i = VK_A; i %3C= VK_Z; i++) %7B%0A            verifyCharacterTyped(i);%0A        %7D%0A        verifyNoMoreInteractions(robot);%0A    %7D%0A%0A    @Test%0A    public void testTypingBigLetters() %7B%0A        //given%0A        String messageWithBigLetters = %22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22;%0A%0A        //when%0A        keyboard.type(messageWithBigLetters);%0A%0A        //then%0A        for (int i = VK_A; i %3C= VK_Z; i++) %7B%0A            verifyCharacterTypedWithShift(i);%0A        %7D%0A        verifyNoMoreInteractions(robot);%0A    %7D%0A%0A    @Test%0A    public void testTypingNumbers() %7B%0A        //given%0A        String messageWithNumbers = %220123456789%22;%0A%0A        //when%0A        keyboard.type(messageWithNumbers);%0A%0A        //then%0A        for (int i = VK_0; i %3C= VK_9; i++) %7B%0A            verifyCharacterTyped(i);%0A        %7D%0A        verifyNoMoreInteractions(robot);%0A    %7D%0A%0A    @Test%0A    public void testTypingSpecialCharactersUnderNumbers() %7B%0A        //given%0A        String messageWithSpecialCharacters = %22)!@#$%25%5E&*(%22;%0A%0A        //when%0A        keyboard.type(messageWithSpecialCharacters);%0A%0A        //then%0A        for (int i = VK_0; i %3C= VK_9; i++) %7B%0A            verifyCharacterTypedWithShift(i);%0A        %7D%0A        verifyNoMoreInteractions(robot
 );%0A 
@@ -2123,31 +2123,43 @@
 rify
-Sequence
+CharacterTypedWithShift
 (int
-...
  keyCode
 s) %7B
@@ -2154,17 +2154,16 @@
  keyCode
-s
 ) %7B%0A    
@@ -2176,28 +2176,31 @@
 rify
-Sequence(keyCodes, 0
+CharacterTyped(VK_SHIFT
 , ke
@@ -2208,16 +2208,8 @@
 Code
-s.length
 );%0A 
@@ -2241,22 +2241,29 @@
 rify
-Sequence
+CharacterTyped
 (int
-%5B%5D
+...
  key
@@ -2271,94 +2271,55 @@
 odes
-, int offset, int length) %7B%0A        if (length == 0) %7B%0A            return;%0A        %7D%0A%0A
+) %7B%0A        for (int keyCode : keyCodes) %7B%0A    
     
@@ -2354,33 +2354,24 @@
 ress(keyCode
-s%5Boffset%5D
 );%0A        v
@@ -2371,60 +2371,74 @@
     
+  
-  verifySequence(keyCodes, offset + 1, length - 1);%0A
+%7D%0A%0A        for (int i = keyCodes.length - 1; i %3E= 0; i--) %7B%0A    
     
@@ -2485,17 +2485,22 @@
 des%5B
-offset%5D);
+i%5D);%0A        %7D
 %0A   

Improve keyboard test to cover more characters