PauseResumeAudioRecorder { public void setAudioFile(final String audioFilePath){ if (audioFilePath==null || audioFilePath.trim().isEmpty()){ throw new IllegalArgumentException("audioFile cannot be null, empty, blank, or directory"); } else if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Recorder cannot have its file changed when it is not in an initialized or prepared state"); } String modifiedAudioFilePath=audioFilePath; if (modifiedAudioFilePath.toLowerCase(Locale.getDefault()).contains(".")){ final String subString=modifiedAudioFilePath.substring(modifiedAudioFilePath.lastIndexOf(".")); modifiedAudioFilePath=modifiedAudioFilePath.replace(subString,".temp"); } else { modifiedAudioFilePath=modifiedAudioFilePath+".temp"; } this.audioFile=modifiedAudioFilePath; currentAudioState.getAndSet(PREPARED_STATE); } 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 testSetAudioFile()throws IllegalAccessException{ pauseResumeAudioRecorder.setAudioFile("/recording.wav"); Assert.assertEquals("Wrong state was set", PauseResumeAudioRecorder.PREPARED_STATE, pauseResumeAudioRecorder.getCurrentState()); Assert.assertEquals("Wrong audio file was set", audioFileField.get(pauseResumeAudioRecorder), "/recording.temp"); pauseResumeAudioRecorder.setAudioFile("/recording"); Assert.assertEquals("Wrong audio file was set", audioFileField.get(pauseResumeAudioRecorder), "/recording.temp"); }
@Test(expected=IllegalArgumentException.class) public void testSetAudioFileNullCase(){pauseResumeAudioRecorder.setAudioFile(null);}
@Test(expected=IllegalArgumentException.class) public void testSetAudioFileEmptyCase(){pauseResumeAudioRecorder.setAudioFile("");}
@Test(expected=IllegalArgumentException.class) public void testSetAudioFileBlankCase(){pauseResumeAudioRecorder.setAudioFile(" ");}
@Test(expected = IllegalStateException.class) public void testSetAudioFileBadState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setAudioFile("/recording.wav"); }