Keypad { public void keyDown(Key key) { pressedKeys[key.ordinal()] = true; byte keyDownValue = getKeyDownValue(key); byte newKeypadValue = (byte) (mmu.readByte(KEYPAD_ADDRESS) & 0xFF & keyDownValue); mmu.writeByte(KEYPAD_ADDRESS, newKeypadValue); updateColumn(); } Keypad(MMU mmu); void keyUp(Key key); void keyDown(Key key);  }
@Test public void shouldEnableAButtonOnKeyButtonADown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.A); assertEquals(0, mmu.readByte(KEYPAD_ADDRESS) & 0x1); }
@Test public void shouldEnableBButtonOnKeyButtonBDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.B); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x2); }
@Test public void shouldEnableRightButtonOnKeyButtonADown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.RIGHT); assertEquals(0, mmu.readByte(KEYPAD_ADDRESS) & 0x1); }
@Test public void shouldEnableLeftButtonOnKeyButtonBDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.LEFT); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x2); }
@Test public void shouldEnableSelectButtonOnKeyButtonADown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.SELECT); assertEquals(0, mmu.readByte(KEYPAD_ADDRESS) & 0x4); }
@Test public void shouldEnableUpButtonOnKeyButtonBDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.UP); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x4); }
@Test public void shouldEnableStartButtonOnKeyButtonADown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.START); assertEquals(0, mmu.readByte(KEYPAD_ADDRESS) & 0x8); }
@Test public void shouldEnableDownButtonOnKeyButtonBDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.DOWN); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x8); }
@Test public void shouldEnableFirstColumnIfAFirstColumnKeyIsDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.A); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x10); }
@Test public void shouldEnableSecondColumnIfAFirstColumnKeyIsDown() { Keypad keypad = givenAKeypad(); keypad.keyDown(Key.LEFT); assertEquals(0x0, mmu.readByte(KEYPAD_ADDRESS) & 0x20); }