Skip to content

Commit 991fdd1

Browse files
author
Mykola Mokhnach
committed
Address issues found by Codacy
1 parent 382c766 commit 991fdd1

8 files changed

+122
-56
lines changed

src/main/java/io/appium/java_client/android/AndroidStartScreenRecordingOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class AndroidStartScreenRecordingOptions
2828
extends BaseStartScreenRecordingOptions<AndroidStartScreenRecordingOptions> {
2929
private Integer bitRate;
3030

31-
public AndroidStartScreenRecordingOptions() {}
31+
public static AndroidStartScreenRecordingOptions startScreenRecordingOptions() {
32+
return new AndroidStartScreenRecordingOptions();
33+
}
3234

3335
/**
3436
* The video bit rate for the video, in megabits per second.

src/main/java/io/appium/java_client/android/AndroidStopScreenRecordingOptions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020

2121
public class AndroidStopScreenRecordingOptions extends
2222
BaseStopScreenRecordingOptions<AndroidStopScreenRecordingOptions> {
23-
public AndroidStopScreenRecordingOptions() {}
23+
24+
public static AndroidStopScreenRecordingOptions stopScreenRecordingOptions() {
25+
return new AndroidStopScreenRecordingOptions();
26+
}
27+
2428
}

src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class IOSStartScreenRecordingOptions
3030
private String videoType;
3131
private String videoQuality;
3232

33-
public IOSStartScreenRecordingOptions() {}
33+
public static IOSStartScreenRecordingOptions startScreenRecordingOptions() {
34+
return new IOSStartScreenRecordingOptions();
35+
}
3436

3537
public enum VideoType {
3638
H264, MP4, FMP4

src/main/java/io/appium/java_client/ios/IOSStopScreenRecordingOptions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020

2121
public class IOSStopScreenRecordingOptions extends
2222
BaseStopScreenRecordingOptions<IOSStopScreenRecordingOptions> {
23-
public IOSStopScreenRecordingOptions() {}
23+
24+
public static IOSStopScreenRecordingOptions stopScreenRecordingOptions() {
25+
return new IOSStopScreenRecordingOptions();
26+
}
27+
2428
}

src/main/java/io/appium/java_client/screenrecording/BaseScreenRecordingOptions.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,61 +24,25 @@
2424
import static java.util.Optional.ofNullable;
2525

2626
public abstract class BaseScreenRecordingOptions<T extends BaseScreenRecordingOptions<T>> {
27-
private String remotePath;
28-
private String user;
29-
private String pass;
30-
private String method;
27+
private ScreenRecordingUploadOptions uploadOptions;
3128

3229
/**
33-
* The path to the remote location, where the resulting video should be uploaded.
30+
* Upload options set for the recorded screen capture.
3431
*
35-
* @param remotePath The path to a writable remote location.
32+
* @param uploadOptions see the documentation on {@link ScreenRecordingUploadOptions}
33+
* for more details.
3634
* @return self instance for chaining.
3735
*/
38-
public T withRemotePath(String remotePath) {
39-
this.remotePath = checkNotNull(remotePath);
40-
//noinspection unchecked
41-
return (T) this;
42-
}
43-
44-
/**
45-
* Sets the credentials for remote ftp/http authentication (if needed).
46-
* This option only has an effect if remotePath is provided.
47-
*
48-
* @param user The name of the user for the remote authentication.
49-
* @param pass The password for the remote authentication.
50-
* @return self instance for chaining.
51-
*/
52-
public T withAuthCredentials(String user, String pass) {
53-
this.user = checkNotNull(user);
54-
this.pass = checkNotNull(pass);
55-
//noinspection unchecked
56-
return (T) this;
57-
}
58-
59-
public enum RequestMethod {
60-
POST, PUT
61-
}
62-
63-
/**
64-
* Sets the method name for http(s) upload. PUT is used by default.
65-
* This option only has an effect if remotePath is provided.
66-
*
67-
* @param method The HTTP method name.
68-
* @return self instance for chaining.
69-
*/
70-
public T withHttpMethod(RequestMethod method) {
71-
this.method = checkNotNull(method).name();
36+
public T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
37+
this.uploadOptions = checkNotNull(uploadOptions);
7238
//noinspection unchecked
7339
return (T) this;
7440
}
7541

7642
public Map<String, Object> build() {
7743
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
78-
ofNullable(remotePath).map(x -> builder.put("remotePath", x));
79-
ofNullable(user).map(x -> builder.put("user", x));
80-
ofNullable(pass).map(x -> builder.put("pass", x));
81-
ofNullable(method).map(x -> builder.put("method", x));
44+
//noinspection unchecked
45+
ofNullable(uploadOptions).map(x -> builder.putAll(x.build()));
8246
return builder.build();
8347
}
8448
}

src/main/java/io/appium/java_client/screenrecording/BaseStartScreenRecordingOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public abstract class BaseStartScreenRecordingOptions<T extends BaseStartScreenR
3030
private Duration timeLimit;
3131

3232
/**
33-
* The path to the remote location, where the resulting video should be uploaded.
33+
* The remotePath upload option is the path to the remote location,
34+
* where the resulting video should be uploaded.
3435
* The following protocols are supported: http/https (multipart), ftp.
3536
* Missing value (the default setting) means the content of the resulting
3637
* file should be encoded as Base64 and passed as the endpoint response value, but
@@ -39,13 +40,14 @@ public abstract class BaseStartScreenRecordingOptions<T extends BaseStartScreenR
3940
* This option only has an effect if there is a screen recording session in progress
4041
* and forced restart is not enabled (the default setting).
4142
*
42-
* @param remotePath The path to a writable remote location (ftp or http(s)).
43+
* @param uploadOptions see the documentation on {@link ScreenRecordingUploadOptions}
44+
* for more details.
4345
* @return self instance for chaining.
4446
*/
4547
@Override
46-
public T withRemotePath(String remotePath) {
48+
public T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
4749
//noinspection unchecked
48-
return (T) super.withRemotePath(remotePath);
50+
return (T) super.withUploadOptions(uploadOptions);
4951
}
5052

5153
/**

src/main/java/io/appium/java_client/screenrecording/BaseStopScreenRecordingOptions.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ public abstract class BaseStopScreenRecordingOptions<T extends BaseStopScreenRec
2020
extends BaseScreenRecordingOptions<BaseStopScreenRecordingOptions<T>> {
2121

2222
/**
23-
* The path to the remote location, where the resulting video should be uploaded.
23+
* The remotePath upload option is the path to the remote location,
24+
* where the resulting video should be uploaded.
2425
* The following protocols are supported: http/https (multipart), ftp.
2526
* Missing value (the default setting) means the content of resulting
2627
* file should be encoded as Base64 and passed as the endpoint response value, but
2728
* an exception will be thrown if the generated media file is too big to
2829
* fit into the available process memory.
2930
*
30-
* @param remotePath The path to a writable remote location (ftp or http(s)).
31+
* @param uploadOptions see the documentation on {@link ScreenRecordingUploadOptions}
32+
* for more details.
3133
* @return self instance for chaining.
3234
*/
33-
public T withRemotePath(String remotePath) {
35+
@Override
36+
public T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
3437
//noinspection unchecked
35-
return (T) super.withRemotePath(remotePath);
38+
return (T) super.withUploadOptions(uploadOptions);
3639
}
3740
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.screenrecording;
18+
19+
import com.google.common.collect.ImmutableMap;
20+
21+
import java.util.Map;
22+
23+
import static com.google.common.base.Preconditions.checkNotNull;
24+
import static java.util.Optional.ofNullable;
25+
26+
public class ScreenRecordingUploadOptions {
27+
private String remotePath;
28+
private String user;
29+
private String pass;
30+
private String method;
31+
32+
public static ScreenRecordingUploadOptions uploadOptions() {
33+
return new ScreenRecordingUploadOptions();
34+
}
35+
36+
/**
37+
* The path to the remote location, where the resulting video should be uploaded.
38+
*
39+
* @param remotePath The path to a writable remote location.
40+
* @return self instance for chaining.
41+
*/
42+
public ScreenRecordingUploadOptions withRemotePath(String remotePath) {
43+
this.remotePath = checkNotNull(remotePath);
44+
return this;
45+
}
46+
47+
/**
48+
* Sets the credentials for remote ftp/http authentication (if needed).
49+
* This option only has an effect if remotePath is provided.
50+
*
51+
* @param user The name of the user for the remote authentication.
52+
* @param pass The password for the remote authentication.
53+
* @return self instance for chaining.
54+
*/
55+
public ScreenRecordingUploadOptions withAuthCredentials(String user, String pass) {
56+
this.user = checkNotNull(user);
57+
this.pass = checkNotNull(pass);
58+
return this;
59+
}
60+
61+
public enum RequestMethod {
62+
POST, PUT
63+
}
64+
65+
/**
66+
* Sets the method name for http(s) upload. PUT is used by default.
67+
* This option only has an effect if remotePath is provided.
68+
*
69+
* @param method The HTTP method name.
70+
* @return self instance for chaining.
71+
*/
72+
public ScreenRecordingUploadOptions withHttpMethod(RequestMethod method) {
73+
this.method = checkNotNull(method).name();
74+
return this;
75+
}
76+
77+
public Map<String, Object> build() {
78+
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
79+
ofNullable(remotePath).map(x -> builder.put("remotePath", x));
80+
ofNullable(user).map(x -> builder.put("user", x));
81+
ofNullable(pass).map(x -> builder.put("pass", x));
82+
ofNullable(method).map(x -> builder.put("method", x));
83+
return builder.build();
84+
}
85+
}

0 commit comments

Comments
 (0)