@Test
public void testStopRecording()throws IllegalAccessException,NoSuchFieldException, InterruptedException{

    PauseResumeAudioRecorder pauseResumeAudioRecorder=new PauseResumeAudioRecorder();
    pauseResumeAudioRecorder.setAudioFile(Environment.getExternalStorageDirectory() + "/recording.wav");
    pauseResumeAudioRecorder.setChannel(AudioFormat.CHANNEL_IN_STEREO);
    pauseResumeAudioRecorder.setSampleRate(44100);
    pauseResumeAudioRecorder.setAudioEncoding(AudioFormat.ENCODING_PCM_8BIT);
    pauseResumeAudioRecorder.startRecording();
    Thread.sleep(100);
    audioRecordThreadField=currentAudioRecordingThreadField.get(pauseResumeAudioRecorder).getClass().getDeclaredField("currentAudioRecording");
    audioRecordThreadField.setAccessible(true);
    AudioRecord audioRecord=(AudioRecord)audioRecordThreadField.get(currentAudioRecordingThreadField.get(pauseResumeAudioRecorder));
    ShadowAudioRecord shadowAudioRecord=Robolectric.shadowOf_(audioRecord);
    pauseResumeAudioRecorder.stopRecording();
    Thread.sleep(5000);//Give it time to convert the file to wav and delete PCM.
    Assert.assertEquals("Wrong state was set", PauseResumeAudioRecorder.STOPPED_STATE, pauseResumeAudioRecorder.getCurrentState());
    Assert.assertFalse("PCM file still exists", new File(Environment.getExternalStorageDirectory() + "/recording.pcm").exists());
    Assert.assertTrue("WAV file does not exist", new File(Environment.getExternalStorageDirectory() + "/recording.wav").exists());
    Assert.assertFalse("AudioRecord is still recording",shadowAudioRecord.isRecording);
    new File(Environment.getExternalStorageDirectory() + "/recording.wav").delete();
}