MediaSyncHelper { public InputStream getAudio(BaseModel baseModel) throws IOException { String apiModel = baseModel.getClass().getSimpleName().toLowerCase(); String audioUrlPath = String.format("/%s/%s/audio", apiModel, baseModel.optString("_id")); return entityHttpDao.getResourceStream(audioUrlPath); } MediaSyncHelper(EntityHttpDao<? extends BaseModel> entityHttpDao, RapidFtrApplication context); void addMultiMediaFilesToTheRequestParameters(BaseModel baseModel, Map<String, String> requestParameters); void setPhoto(BaseModel baseModel); void getPhotoFromServer(BaseModel baseModel, PhotoCaptureHelper photoCaptureHelper, String fileName); void setAudio(BaseModel baseModel); InputStream getAudio(BaseModel baseModel);  }
@Test public void shouldFetchAudioFromServer() throws JSONException, IOException, GeneralSecurityException { Child child = new Child("id1", "user1", "{ '_id' : '1234abcd' ,'recorded_audio' : 'audio_file_name'}"); getFakeHttpLayer().setDefaultHttpResponse(200, "audio stream"); getFakeHttpLayer().addHttpResponseRule("http: String response = CharStreams.toString(new InputStreamReader(new MediaSyncHelper(childHttpDao, application).getAudio(child))); assertEquals("OK", response); }
@Test public void shouldBuildAudioUrlFromChildModel() throws IOException { EntityHttpDao<Child> spyDao = spy(new EntityHttpDao<Child>(application)); MediaSyncHelper helper = new MediaSyncHelper(spyDao, application); Child child = new Child(); child.put("_id", "1234"); doReturn(null).when(spyDao).getResourceStream(any(String.class)); helper.getAudio(child); verify(spyDao).getResourceStream("/child/1234/audio"); }
@Test public void shouldBuildAudioUrlFromEnquiryModel() throws IOException, JSONException { EntityHttpDao<Child> spyDao = spy(new EntityHttpDao<Child>(application)); MediaSyncHelper helper = new MediaSyncHelper(spyDao, application); Enquiry enquiry = new Enquiry("{}"); enquiry.put("_id", "1234"); doReturn(null).when(spyDao).getResourceStream(any(String.class)); helper.getAudio(enquiry); verify(spyDao).getResourceStream("/enquiry/1234/audio"); }