Skip to content

Commit 8feb425

Browse files
committed
CR
1 parent a942d67 commit 8feb425

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ public class AppiumCommandExecutor extends HttpCommandExecutor {
5858

5959
private final Optional<DriverService> serviceOptional;
6060
@Getter
61-
private final Factory httpClientFactory;
62-
@Getter
6361
private final AppiumClientConfig appiumClientConfig;
6462

6563
/**
@@ -81,7 +79,6 @@ public AppiumCommandExecutor(
8179
);
8280
serviceOptional = ofNullable(service);
8381

84-
this.httpClientFactory = ofNullable(httpClientFactory).orElseGet(HttpCommandExecutor::getDefaultClientFactory);
8582
this.appiumClientConfig = appiumClientConfig;
8683
}
8784

@@ -141,6 +138,10 @@ public Map<String, CommandInfo> getAdditionalCommands() {
141138
return getPrivateFieldValue(HttpCommandExecutor.class, "additionalCommands", Map.class);
142139
}
143140

141+
public Factory getHttpClientFactory() {
142+
return getPrivateFieldValue(HttpCommandExecutor.class, "httpClientFactory", Factory.class);
143+
}
144+
144145
@Nullable
145146
protected CommandCodec<HttpRequest> getCommandCodec() {
146147
return this.commandCodec;
@@ -165,8 +166,8 @@ protected HttpClient getClient() {
165166
* @param serverUrl A url to override.
166167
*/
167168
protected void overrideServerUrl(URL serverUrl) {
168-
setPrivateFieldValue(HttpCommandExecutor.class, "client",
169-
this.httpClientFactory.createClient(this.appiumClientConfig.baseUrl(serverUrl)));
169+
HttpClient newClient = getHttpClientFactory().createClient(appiumClientConfig.baseUrl(serverUrl));
170+
setPrivateFieldValue(HttpCommandExecutor.class, "client", newClient);
170171
}
171172

172173
private Response createSession(Command command) throws IOException {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.appium.java_client.remote;
2+
3+
import io.appium.java_client.AppiumClientConfig;
4+
import io.appium.java_client.MobileCommand;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
12+
class AppiumCommandExecutorTest {
13+
private static final String APPIUM_URL = "https://appium.exaple.com";
14+
15+
private AppiumCommandExecutor createExecutor() {
16+
URL baseUrl;
17+
try {
18+
baseUrl = new URL(APPIUM_URL);
19+
} catch (MalformedURLException e) {
20+
throw new AssertionError(e);
21+
}
22+
AppiumClientConfig clientConfig = AppiumClientConfig.defaultConfig().baseUrl(baseUrl);
23+
return new AppiumCommandExecutor(MobileCommand.commandRepository, clientConfig);
24+
}
25+
26+
@Test
27+
void getAdditionalCommands() {
28+
assertNotNull(createExecutor().getAdditionalCommands());
29+
}
30+
31+
@Test
32+
void getHttpClientFactory() {
33+
assertNotNull(createExecutor().getHttpClientFactory());
34+
}
35+
36+
@Test
37+
void overrideServerUrl() {
38+
assertDoesNotThrow(() -> createExecutor().overrideServerUrl(new URL("https://direct.example.com")));
39+
}
40+
}

0 commit comments

Comments
 (0)