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.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;

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

        //when
        keyboard.type(sampleMessage);

        //then
        InOrder order = inOrder(robot);
        order.verify(robot).keyPress(VK_SHIFT);
        order.verify(robot).keyPress(VK_A);
        order.verify(robot).keyRelease(VK_A);
        order.verify(robot).keyRelease(VK_SHIFT);
        order.verify(robot).keyPress(VK_B);
        order.verify(robot).keyRelease(VK_B);
        order.verify(robot).keyPress(VK_SHIFT);
        order.verify(robot).keyPress(VK_C);
        order.verify(robot).keyRelease(VK_C);
        order.verify(robot).keyRelease(VK_SHIFT);
        verifyNoMoreInteractions(robot);
    }
}
@@ -198,24 +198,50 @@
  java.awt.*;
+%0A%0Aimport org.junit.Before;
 %0Aimport org.
@@ -567,16 +567,113 @@
 board;%0A%0A
+    InOrder order;%0A%0A    @Before%0A    public void setUp() %7B%0A        order = inOrder(robot);%0A    %7D%0A%0A
     @Tes
@@ -852,85 +852,81 @@
     
-InOrder order = inOrder(robot);%0A        order.verify(robot).key
+verifySequencePressed(VK_SHIFT, VK_A);%0A        verifySequence
 Press
+ed
 (VK_
-SHIFT
+B
 );%0A 
@@ -936,456 +936,607 @@
     
-order.verify(robot).key
+verifySequence
 Press
+ed
 (VK_
-A);%0A        order.verify(robot).keyRelease(VK_A
+SHIFT, VK_C);%0A        verifyNoMoreInteractions(robot
 );%0A    
+%7D%0A%0A
     
-order.verify(robot).keyRelease(VK_SHIFT
+private void verifySequencePressed(int... sequence) %7B%0A        verifySequence(sequence
 );%0A    
+%7D%0A%0A
     
-order.verify(robot).keyPress(VK_B);%0A        order.verify(robot).keyRelease(VK_B
+private void verifySequence(int... keyCodes) %7B%0A        verifySequence(keyCodes, 0, keyCodes.length
 );%0A    
+%7D%0A%0A
     
-order.verify(robot).keyPress(VK_SHIFT);%0A        order.verify(robot).keyPress(VK_C);%0A        order.verify(robot).keyRelease(VK_C);%0A        order.verify(robot).keyRelease(VK_SHIFT);%0A        verifyNoMoreInteractions(robot
+private void verifySequence(int%5B%5D keyCodes, int offset, int length) %7B%0A        if (length == 0) %7B%0A            return;%0A        %7D%0A%0A        order.verify(robot).keyPress(keyCodes%5Boffset%5D);%0A        verifySequence(keyCodes, offset + 1, length - 1);%0A        order.verify(robot).keyRelease(keyCodes%5Boffset%5D
 );%0A 

Test improvements