PauseResumeAudioRecorder { public void setChannel(final int channelConfig){ if(channelConfig != AudioFormat.CHANNEL_IN_MONO && channelConfig !=AudioFormat.CHANNEL_IN_STEREO && channelConfig != AudioFormat.CHANNEL_IN_DEFAULT){ throw new IllegalArgumentException("Invalid channel given."); } else if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Recorder cannot have its file changed when it is in an initialized or prepared state"); } this.channelConfig=channelConfig; } 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 testSetChannel()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); pauseResumeAudioRecorder.setChannel(AudioFormat.CHANNEL_IN_STEREO); Assert.assertEquals("Invalid channel config stereo",AudioFormat.CHANNEL_IN_STEREO,channelConfigField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setChannel(AudioFormat.CHANNEL_IN_MONO); Assert.assertEquals("Invalid channel config mono", AudioFormat.CHANNEL_IN_MONO, channelConfigField.get(pauseResumeAudioRecorder)); pauseResumeAudioRecorder.setChannel(AudioFormat.CHANNEL_IN_DEFAULT); Assert.assertEquals("Invalid channel config default", AudioFormat.CHANNEL_IN_DEFAULT, channelConfigField.get(pauseResumeAudioRecorder)); }
@Test(expected=IllegalArgumentException.class) public void testSetChannelBadParameter(){pauseResumeAudioRecorder.setChannel(Integer.MAX_VALUE);}
@Test(expected = IllegalStateException.class) public void testSetChannelBadState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setChannel(AudioFormat.CHANNEL_IN_MONO); }