PauseResumeAudioRecorder { public void setSampleRate(final int sampleRateInHertz){ if (sampleRateInHertz!=DEFAULT_AUDIO_SAMPLE_RATE_HERTZ && sampleRateInHertz !=22050 && sampleRateInHertz != 16000 && sampleRateInHertz !=11025){ throw new IllegalArgumentException("Invalid sample rate given"); } else if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Recorder cannot have its sample rate changed when it is not in an initialized or prepared state"); } this.sampleRateInHertz=sampleRateInHertz; } 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 testSetSampleRate()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); pauseResumeAudioRecorder.setSampleRate(22050); Assert.assertEquals("Sample rate is incorrect 22050", 22050, sampleRateInHertzField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setSampleRate(16000); Assert.assertEquals("Sample rate is incorrect 16000", 16000, sampleRateInHertzField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setSampleRate(11025); Assert.assertEquals("Sample rate is incorrect 11025", 11025, sampleRateInHertzField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setSampleRate(44100); Assert.assertEquals("Sample rate is incorrect 44100", 44100, sampleRateInHertzField.get(pauseResumeAudioRecorder)); }
@Test(expected = IllegalArgumentException.class) public void testSetSampleRateBadInput(){pauseResumeAudioRecorder.setSampleRate(0);}
@Test(expected = IllegalStateException.class) public void testSetSampleRateBadState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setSampleRate(44100); }