ServerWrapper { public String uploadVideo(File video) { HttpUrl url = new HttpUrl.Builder() .scheme(this.Scheme) .host(this.Host) .addPathSegment("upload") .build(); Log.d("ServerWrapper", "uploadVideo(), file exists: " + video.exists()); Log.d("ServerWrapper", "File: " + video); RequestBody requestBody = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart( "file", video.getName(), RequestBody.create(MediaType.parse("video/"), video)) .build(); Request request = new Request.Builder() .url(url) .post(requestBody) .build(); return this.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 uploadVideo_VideoUploaded_ReturnsVideoId() { final String ExpectedVideoId = "video_id_1"; MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .post() .url("https: .respond(ExpectedVideoId); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); File videoFile = new File("./src/test/java/com/eddex/jackle/jumpcutter/internet/test.mp4"); ServerWrapper server = new ServerWrapper(okHttpClient, null); String videoId = server.uploadVideo(videoFile); Assert.assertEquals(ExpectedVideoId, videoId); }
@Test public void uploadVideo_VideoUploadFailed_ReturnsNull() { MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .post() .url("https: .answer(request -> new Response.Builder().code(404)); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); File videoFile = new File("./src/test/java/com/eddex/jackle/jumpcutter/internet/test.mp4"); ServerWrapper server = new ServerWrapper(okHttpClient, null); String videoId = server.uploadVideo(videoFile); Assert.assertEquals(null, videoId); }