ServerWrapper { public String processVideo(String videoId, SettingsProvider settingsProvider) { ProcessUrlBuilder urlBuilder = new ProcessUrlBuilder() .withHost(this.Host) .withScheme(this.Scheme) .withVideoId(videoId) .withSoundedSpeed(settingsProvider.getSoundSpeed()) .withSilentSpeed(settingsProvider.getSilenceSpeed()) .withSilentThreshold(settingsProvider.getSilenceThreshold()) .withFrameMargin(settingsProvider.getFrameMargin()); if (settingsProvider.getAdvancedOptionsSwitchEnabled()) { urlBuilder .withSampleRate(settingsProvider.getSampleRate()) .withFrameRate(settingsProvider.getFrameRate()) .withFrameQuality(settingsProvider.getFrameQuality()); } HttpUrl url = urlBuilder.build(); Request request = new Request.Builder() .url(url) .get() .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(expected = NullPointerException.class) public void processVideo_NoSettingsProvider_ThrowsNullPointerException() { ServerWrapper server = new ServerWrapper(null, null); server.processVideo(null, null); }
@Test public void processVideo_NoAdvancedOptions_ServerCallAsExpectedAndDownloadIdReturned() { String ExpectedDownloadId = "download_id"; String SoundedSpeed = "1"; String SilentSpeed = "2"; String SilenceThreshold = "3"; String FrameMargin = "4"; MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .get() .url(new ProcessUrlBuilder() .withHost("jumpcutter.letum.ch") .withSoundedSpeed(SoundedSpeed) .withSilentSpeed(SilentSpeed) .withSilentThreshold(SilenceThreshold) .withFrameMargin(FrameMargin) .build() .toString()) .respond(ExpectedDownloadId); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); SettingsProvider settingsProviderMock = Mockito.mock(SettingsProvider.class); when(settingsProviderMock.getSoundSpeed()) .thenReturn(SoundedSpeed); when(settingsProviderMock.getSilenceSpeed()) .thenReturn(SilentSpeed); when(settingsProviderMock.getSilenceThreshold()) .thenReturn(SilenceThreshold); when(settingsProviderMock.getFrameMargin()) .thenReturn(FrameMargin); when(settingsProviderMock.getAdvancedOptionsSwitchEnabled()) .thenReturn(false); ServerWrapper server = new ServerWrapper(okHttpClient, null); String downloadId = server.processVideo(null, settingsProviderMock); Assert.assertEquals(ExpectedDownloadId, downloadId); }
@Test public void processVideo_WithAdvancedOptions_ServerCallAsExpectedAndDownloadIdReturned() { String ExpectedDownloadId = "download_id"; String SoundedSpeed = "1"; String SilentSpeed = "2"; String SilenceThreshold = "3"; String FrameMargin = "4"; String FrameRate = "5"; String FrameQuality = "6"; String SampleRate = "7"; MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .get() .url(new ProcessUrlBuilder() .withHost("jumpcutter.letum.ch") .withSoundedSpeed(SoundedSpeed) .withSilentSpeed(SilentSpeed) .withSilentThreshold(SilenceThreshold) .withFrameMargin(FrameMargin) .withFrameRate(FrameRate) .withFrameQuality(FrameQuality) .withSampleRate(SampleRate) .build() .toString()) .respond(ExpectedDownloadId); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); SettingsProvider settingsProviderMock = Mockito.mock(SettingsProvider.class); when(settingsProviderMock.getSoundSpeed()) .thenReturn(SoundedSpeed); when(settingsProviderMock.getSilenceSpeed()) .thenReturn(SilentSpeed); when(settingsProviderMock.getSilenceThreshold()) .thenReturn(SilenceThreshold); when(settingsProviderMock.getFrameMargin()) .thenReturn(FrameMargin); when(settingsProviderMock.getFrameRate()) .thenReturn(FrameRate); when(settingsProviderMock.getFrameQuality()) .thenReturn(FrameQuality); when(settingsProviderMock.getSampleRate()) .thenReturn(SampleRate); when(settingsProviderMock.getAdvancedOptionsSwitchEnabled()) .thenReturn(true); ServerWrapper server = new ServerWrapper(okHttpClient, null); String downloadId = server.processVideo(null, settingsProviderMock); Assert.assertEquals(ExpectedDownloadId, downloadId); }
@Test public void processVideo_ProcessingFailed_ReturnsNull() { MockInterceptor okHttpMockInterceptor = new MockInterceptor(); okHttpMockInterceptor.addRule() .get() .urlStarts("https: .answer(request -> new Response.Builder().code(500)); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(okHttpMockInterceptor) .build(); ServerWrapper server = new ServerWrapper(okHttpClient, null); SettingsProvider settingsProviderMock = Mockito.mock(SettingsProvider.class); String response = server.processVideo(null, settingsProviderMock); Assert.assertEquals(null, response); }