PauseResumeAudioRecorder { public void setAudioEncoding(final int audioEncoding){ if (audioEncoding !=AudioFormat.ENCODING_PCM_8BIT && audioEncoding !=AudioFormat.ENCODING_PCM_16BIT){ throw new IllegalArgumentException("Invalid encoding"); } else if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Cannot modify audio encoding during a non-prepared and non-initialized state"); } this.audioEncoding=audioEncoding; } 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(expected = IllegalStateException.class) public void testSetAudioEncodingInvalidState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setAudioEncoding(AudioFormat.ENCODING_PCM_8BIT); }
@Test public void testSetAudioEncoding()throws IllegalAccessException{ pauseResumeAudioRecorder.setAudioEncoding(AudioFormat.ENCODING_PCM_8BIT); Assert.assertEquals("audio encoding is incorrect", AudioFormat.ENCODING_PCM_8BIT, audioEncodingField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setAudioEncoding(AudioFormat.ENCODING_PCM_16BIT); Assert.assertEquals("audio encoding is incorrect", AudioFormat.ENCODING_PCM_16BIT, audioEncodingField.get(pauseResumeAudioRecorder)); }
@Test(expected=IllegalArgumentException.class) public void testSetAudioEncodingInvalidInput(){pauseResumeAudioRecorder.setAudioEncoding(0);}