@Test public void close_safeToCallTwice() throws IOException { Speaker speaker = new Speaker(mPwm); speaker.close(); speaker.close(); Mockito.verify(mPwm, times(1)).close(); }
@Override public void close() throws IOException { if (mPwm != null) { try { mPwm.close(); } finally { mPwm = null; } } }
Speaker implements AutoCloseable { @Override public void close() throws IOException { if (mPwm != null) { try { mPwm.close(); } finally { mPwm = null; } } } }
Speaker implements AutoCloseable { @Override public void close() throws IOException { if (mPwm != null) { try { mPwm.close(); } finally { mPwm = null; } } } Speaker(String pin); @VisibleForTesting  Speaker(Pwm device); }
Speaker implements AutoCloseable { @Override public void close() throws IOException { if (mPwm != null) { try { mPwm.close(); } finally { mPwm = null; } } } Speaker(String pin); @VisibleForTesting  Speaker(Pwm device); @Override void close(); void play(double frequency); void stop(); }
Speaker implements AutoCloseable { @Override public void close() throws IOException { if (mPwm != null) { try { mPwm.close(); } finally { mPwm = null; } } } Speaker(String pin); @VisibleForTesting  Speaker(Pwm device); @Override void close(); void play(double frequency); void stop();  }