PauseResumeAudioRecorder { public void setOnTimeCompletionListener(final OnTimeCompletionListener onTimeCompletionListener) { if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Cannot modify onTimeCompletionListener during a non-prepared and non-initialized state"); } this.onTimeCompletionListener = onTimeCompletionListener; } PauseResumeAudioRecorder(); void setOnFileSizeReachedListener(final OnFileSizeReachedListener onFileSizeReachedListener); void setMaxFileSizeInBytes(final long maxFileSizeInBytes); void setOnTimeCompletionListener(final OnTimeCompletionListener onTimeCompletionListener); void setMaxTimeInMillis(final long maxTimeInMillis); void setAudioEncoding(final int audioEncoding); void setAudioFile(final String audioFilePath); void setSampleRate(final int sampleRateInHertz); void setChannel(final int channelConfig); int getCurrentState(); void startRecording(); void pauseRecording(); void resumeRecording(); void stopRecording(); static final int STOPPED_STATE; static final int INITIALIZED_STATE; static final int PREPARED_STATE; static final int RECORDING_STATE; static final int PAUSED_STATE; static final int ERROR_STATE; }
@Test public void testSetOnTimeCompletionListener()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.INITIALIZED_STATE)); final OnMaxTimeCompletionListener onMaxTimeCompletionListener=new OnMaxTimeCompletionListener(); pauseResumeAudioRecorder.setOnTimeCompletionListener(onMaxTimeCompletionListener); Assert.assertEquals("Listener incorrect", onMaxTimeCompletionListener, onTimeCompletionListenerField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setOnTimeCompletionListener(null); Assert.assertEquals("Listener incorrect null case", null, onTimeCompletionListenerField.get(pauseResumeAudioRecorder)); }
@Test(expected = IllegalStateException.class) public void testSetOnTimeCompletionListenerInvalidState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setOnTimeCompletionListener(null); }