forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserWebDriverContainerSeleniumAddressTest.java
More file actions
53 lines (39 loc) · 1.69 KB
/
Copy pathBrowserWebDriverContainerSeleniumAddressTest.java
File metadata and controls
53 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.testcontainers.containers;
import org.junit.jupiter.api.Test;
import java.net.MalformedURLException;
import java.net.URL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class BrowserWebDriverContainerSeleniumAddressTest {
@Test
void getSeleniumAddressReturnsUrlBuiltFromHostAndMappedPort() throws MalformedURLException {
BrowserWebDriverContainer<?> container = new FixedAddressBrowserWebDriverContainer("localhost", 32768);
assertThat(container.getSeleniumAddress()).isEqualTo(new URL("http", "localhost", 32768, "/wd/hub"));
}
@Test
void getSeleniumAddressThrowsContainerLaunchExceptionWhenUrlCannotBeConstructed() {
BrowserWebDriverContainer<?> container = new FixedAddressBrowserWebDriverContainer("http://bad", 32768);
assertThatThrownBy(container::getSeleniumAddress)
.isInstanceOf(ContainerLaunchException.class)
.hasMessage("Could not construct Selenium address")
.hasCauseInstanceOf(MalformedURLException.class);
}
private static class FixedAddressBrowserWebDriverContainer
extends BrowserWebDriverContainer<FixedAddressBrowserWebDriverContainer> {
private final String host;
private final int mappedPort;
FixedAddressBrowserWebDriverContainer(String host, int mappedPort) {
super();
this.host = host;
this.mappedPort = mappedPort;
}
@Override
public String getHost() {
return host;
}
@Override
public Integer getMappedPort(int originalPort) {
return mappedPort;
}
}
}