ServerWrapper { public String downloadYouTubeVideo(String youtubeUrl) { HttpUrl url = new HttpUrl.Builder() .scheme(this.Scheme) .host(this.Host) .addPathSegment("youtube") .addQueryParameter("url", youtubeUrl) .build(); Request request = new Request.Builder() .url(url) .get() .build(); return getStringResponseFromServer(request); } @Inject  ServerWrapper(OkHttpClient okHttpClient, FileSystemWrapper filesystemWrapper); Boolean ping(); String uploadVideo(File video); String downloadYouTubeVideo(String youtubeUrl); String processVideo(String videoId, SettingsProvider settingsProvider); boolean downloadVideo(String downloadId); public boolean HasError; }
@Test public void downloadYouTubeVideo_NoErrors_ReturnsVideoId() { final String ExpectedVideoId = "video_id_1"; final String YouTubeUrl = "youtube.com123"; MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .get() .urlStarts("https: .respond(ExpectedVideoId); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); ServerWrapper server = new ServerWrapper(okHttpClient, null); String videoId = server.downloadYouTubeVideo(YouTubeUrl); Assert.assertEquals(ExpectedVideoId, videoId); }
@Test public void downloadYouTubeVideo_VideoUploadFailed_ReturnsNull() { MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .get() .urlStarts("https: .answer(request -> new Response.Builder().code(404)); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); ServerWrapper server = new ServerWrapper(okHttpClient, null); String videoId = server.downloadYouTubeVideo(null); Assert.assertEquals(null, videoId); }