PauseResumeAudioRecorder { public void setMaxTimeInMillis(final long maxTimeInMillis){ if (maxTimeInMillis<1000 || maxTimeInMillis>PcmWavConverter.MAX_TIME_WAV_FILE_MILLIS){ throw new IllegalArgumentException("Invalid max time given"); } else if (currentAudioState.get()!=PREPARED_STATE && currentAudioState.get()!=INITIALIZED_STATE ){ throw new IllegalStateException("Cannot modify maxTimeInMillis during a non-prepared and non-initialized state"); } this.maxTimeInMillis=maxTimeInMillis; this.remainingMaxTimeInMillis=maxTimeInMillis; } 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 testSetMaxTimeInMillis()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); pauseResumeAudioRecorder.setMaxTimeInMillis(2000); Assert.assertEquals("remainingMaxTime incorrect", 2000, (long) remainingMaxTimeInMillisField.get(pauseResumeAudioRecorder)); Assert.assertEquals("maxTime incorrect", 2000, (long) maxTimeInMillisField.get(pauseResumeAudioRecorder)); }
@Test(expected=IllegalArgumentException.class) public void testSetMaxTimeInMillisMin(){new PauseResumeAudioRecorder().setMaxTimeInMillis(999);}
@Test(expected=IllegalArgumentException.class) public void testSetMaxTimeInMillisMax(){new PauseResumeAudioRecorder().setMaxTimeInMillis(PcmWavConverter.MAX_TIME_WAV_FILE_MILLIS+1);}
@Test(expected=IllegalStateException.class) public void testSetMaxTimeInMillisBadState()throws IllegalAccessException{ PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder(); currentAudioStateField.set(pauseResumeAudioRecorder, new AtomicInteger(PauseResumeAudioRecorder.RECORDING_STATE)); pauseResumeAudioRecorder.setMaxTimeInMillis(1000); }