I have this code in Java:
public class KeyboardListener implements KeyListener
{
public void keyPressed(final KeyEvent the_event) {
final int key = the_event.getKeyCode();
if (key == KeyEvent.VK_UP && game.my_snake_direction != 40)
{
game.my_snake_direction = key;
game.moveSnake(KeyDirections.UP.getDirection());
}
// ...
And I'm trying to test the KeyPress, but I don't know how to create the event or the component in the test code. In my code I haven't any component. Should I to create a component in test code?
@Test
public void KeyPressTest() {
KeyboardListener KL = new KeyboardListener();
KeyEvent the_event; //=new KeyEvent(..fail component..);
KL.KeyPressed(the_event); //here the_event isn't init
PS: sorry for my english.
Thank you
Aucun commentaire:
Enregistrer un commentaire