@Test public void close_safeToCallTwice() throws IOException { Button button = new Button(mGpio, LogicState.PRESSED_WHEN_HIGH); button.close(); button.close(); Mockito.verify(mGpio, times(1)).close(); }
@Override public void close() throws IOException { removeDebounceCallback(); mListener = null; if (mButtonGpio != null) { mButtonGpio.unregisterGpioCallback(mInterruptCallback); try { mButtonGpio.close(); } finally { mButtonGpio = null; } } }
Button implements AutoCloseable { @Override public void close() throws IOException { removeDebounceCallback(); mListener = null; if (mButtonGpio != null) { mButtonGpio.unregisterGpioCallback(mInterruptCallback); try { mButtonGpio.close(); } finally { mButtonGpio = null; } } } }
Button implements AutoCloseable { @Override public void close() throws IOException { removeDebounceCallback(); mListener = null; if (mButtonGpio != null) { mButtonGpio.unregisterGpioCallback(mInterruptCallback); try { mButtonGpio.close(); } finally { mButtonGpio = null; } } } Button(String pin, LogicState logicLevel); @VisibleForTesting  Button(Gpio buttonGpio, LogicState logicLevel); }
Button implements AutoCloseable { @Override public void close() throws IOException { removeDebounceCallback(); mListener = null; if (mButtonGpio != null) { mButtonGpio.unregisterGpioCallback(mInterruptCallback); try { mButtonGpio.close(); } finally { mButtonGpio = null; } } } Button(String pin, LogicState logicLevel); @VisibleForTesting  Button(Gpio buttonGpio, LogicState logicLevel); String getName(); void setOnButtonEventListener(OnButtonEventListener listener); void setDebounceDelay(long delay); @Override void close(); }
Button implements AutoCloseable { @Override public void close() throws IOException { removeDebounceCallback(); mListener = null; if (mButtonGpio != null) { mButtonGpio.unregisterGpioCallback(mInterruptCallback); try { mButtonGpio.close(); } finally { mButtonGpio = null; } } } Button(String pin, LogicState logicLevel); @VisibleForTesting  Button(Gpio buttonGpio, LogicState logicLevel); String getName(); void setOnButtonEventListener(OnButtonEventListener listener); void setDebounceDelay(long delay); @Override void close();  }