### Question:
KeyboardState { public EnumSet<Key> getKeysReleasedSince(final KeyboardState previous) { final EnumSet<Key> result = EnumSet.copyOf(previous._keysDown); result.removeAll(_keysDown); return result; } KeyboardState(final EnumSet<Key> keysDown, final KeyEvent keyEvent); boolean isDown(final Key key); boolean isAllDown(final Key... keys); boolean isAtLeastOneDown(final Key... keys); Set<Key> getKeysDown(); KeyEvent getKeyEvent(); EnumSet<Key> getKeysReleasedSince(final KeyboardState previous); EnumSet<Key> getKeysPressedSince(final KeyboardState previous); EnumSet<Key> getKeysHeldSince(final KeyboardState previous); @Override String toString(); static final KeyboardState NOTHING; }### Answer:
@Test public void testKeysReleased1() throws Exception { ks1 = new KeyboardState(EnumSet.of(Key.A, Key.B), KeyEvent.NOTHING); ks2 = new KeyboardState(EnumSet.of(Key.A, Key.E), KeyEvent.NOTHING); final EnumSet<Key> released = ks2.getKeysReleasedSince(ks1); assertEquals("1 key", 1, released.size()); assertTrue("b released", released.contains(Key.B)); }
@Test public void testKeysReleased2() throws Exception { ks1 = new KeyboardState(EnumSet.of(Key.A, Key.B), KeyEvent.NOTHING); ks2 = new KeyboardState(EnumSet.noneOf(Key.class), KeyEvent.NOTHING); final EnumSet<Key> released = ks2.getKeysReleasedSince(ks1); assertEquals("2 key", 2, released.size()); assertTrue("a released", released.contains(Key.A)); assertTrue("b released", released.contains(Key.B)); }