@Test void testUploadDirectoryHappyScenarioShouldUploadDirectory() throws Exception { when(mockContext.getDir()).thenReturn("/mock/dir"); when(mockPathToUpload.toFile()) .thenReturn(new File(PodUpload.class.getResource("/upload").getFile())); when(mockClient.newWebSocket(any(), any())).thenAnswer(newWebSocket -> { final PodUploadWebSocketListener wsl = newWebSocket.getArgument(1, PodUploadWebSocketListener.class); wsl.onOpen(mockWebSocket, null); wsl.onMessage(mockWebSocket, ByteString.of((byte) 0)); when(mockWebSocket.close(anyInt(), anyString())).thenAnswer(close -> { wsl.onClosed(mockWebSocket, close.getArgument(0), close.getArgument(1)); return true; }); return mockWebSocket; }); final boolean result = PodUpload.upload(mockClient, mockContext, operationSupport, mockPathToUpload); assertThat(result, equalTo(true)); verify(mockPathToUpload, atLeast(1)).toFile(); verify(mockClient, times(1)).newWebSocket(argThat(request -> { assertThat(request.url().toString(), equalTo("https: return true; }), any(PodUploadWebSocketListener.class)); verify(mockWebSocket, atLeast(1)).send(any(ByteString.class)); verify(mockWebSocket, times(0)).send(anyString()); }
public static boolean upload(OkHttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException { if (Utils.isNotNullOrEmpty(context.getFile()) && pathToUpload.toFile().isFile()) { return uploadFile(client, context, operationSupport, pathToUpload); } else if (Utils.isNotNullOrEmpty(context.getDir()) && pathToUpload.toFile().isDirectory()) { return uploadDirectory(client, context, operationSupport, pathToUpload); } throw new IllegalArgumentException("Provided arguments are not valid (file, directory, path)"); }
PodUpload { public static boolean upload(OkHttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException { if (Utils.isNotNullOrEmpty(context.getFile()) && pathToUpload.toFile().isFile()) { return uploadFile(client, context, operationSupport, pathToUpload); } else if (Utils.isNotNullOrEmpty(context.getDir()) && pathToUpload.toFile().isDirectory()) { return uploadDirectory(client, context, operationSupport, pathToUpload); } throw new IllegalArgumentException("Provided arguments are not valid (file, directory, path)"); } }
PodUpload { public static boolean upload(OkHttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException { if (Utils.isNotNullOrEmpty(context.getFile()) && pathToUpload.toFile().isFile()) { return uploadFile(client, context, operationSupport, pathToUpload); } else if (Utils.isNotNullOrEmpty(context.getDir()) && pathToUpload.toFile().isDirectory()) { return uploadDirectory(client, context, operationSupport, pathToUpload); } throw new IllegalArgumentException("Provided arguments are not valid (file, directory, path)"); } private  PodUpload(); }
PodUpload { public static boolean upload(OkHttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException { if (Utils.isNotNullOrEmpty(context.getFile()) && pathToUpload.toFile().isFile()) { return uploadFile(client, context, operationSupport, pathToUpload); } else if (Utils.isNotNullOrEmpty(context.getDir()) && pathToUpload.toFile().isDirectory()) { return uploadDirectory(client, context, operationSupport, pathToUpload); } throw new IllegalArgumentException("Provided arguments are not valid (file, directory, path)"); } private  PodUpload(); static boolean upload(OkHttpClient client, PodOperationContext context,
    OperationSupport operationSupport, Path pathToUpload); }
PodUpload { public static boolean upload(OkHttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException { if (Utils.isNotNullOrEmpty(context.getFile()) && pathToUpload.toFile().isFile()) { return uploadFile(client, context, operationSupport, pathToUpload); } else if (Utils.isNotNullOrEmpty(context.getDir()) && pathToUpload.toFile().isDirectory()) { return uploadDirectory(client, context, operationSupport, pathToUpload); } throw new IllegalArgumentException("Provided arguments are not valid (file, directory, path)"); } private  PodUpload(); static boolean upload(OkHttpClient client, PodOperationContext context,
    OperationSupport operationSupport, Path pathToUpload);  }