Skip to content

Commit 4f390d7

Browse files
committed
Removed custom AutoClosableExtension.
1 parent 14c9942 commit 4f390d7

File tree

13 files changed

+59
-134
lines changed

13 files changed

+59
-134
lines changed

client/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
<artifactId>jsoup</artifactId>
3838
</dependency>
3939

40-
<dependency>
41-
<groupId>dev.rilling</groupId>
42-
<artifactId>webmention4j-common-test</artifactId>
43-
<version>${project.version}</version>
44-
<scope>test</scope>
45-
</dependency>
4640
<dependency>
4741
<groupId>org.junit.jupiter</groupId>
4842
<artifactId>junit-jupiter-api</artifactId>

client/src/test/java/dev/rilling/webmention4j/client/internal/EndpointDiscoveryServiceIT.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
44
import dev.rilling.webmention4j.client.internal.link.HeaderLinkParser;
55
import dev.rilling.webmention4j.client.internal.link.HtmlLinkParser;
6-
import dev.rilling.webmention4j.common.test.AutoClosableExtension;
76
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
87
import org.apache.hc.client5.http.impl.classic.HttpClients;
98
import org.apache.hc.core5.http.HttpStatus;
9+
import org.junit.jupiter.api.AutoClose;
1010
import org.junit.jupiter.api.DisplayName;
1111
import org.junit.jupiter.api.Test;
1212
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -26,9 +26,8 @@ class EndpointDiscoveryServiceIT {
2626
.options(wireMockConfig().dynamicPort())
2727
.build();
2828

29-
@RegisterExtension
30-
static final AutoClosableExtension<CloseableHttpClient> HTTP_CLIENT_EXTENSION = new AutoClosableExtension<>(
31-
HttpClients::createDefault);
29+
@AutoClose
30+
static final CloseableHttpClient HTTP_CLIENT = HttpClients.createDefault();
3231

3332
final EndpointDiscoveryService endpointDiscoveryService = new EndpointDiscoveryService(new HeaderLinkParser(),
3433
new HtmlLinkParser());
@@ -42,13 +41,13 @@ void throwsOnError() {
4241
TARGET_SERVER.stubFor(get("/unauthorized").willReturn(aResponse().withStatus(HttpStatus.SC_UNAUTHORIZED)));
4342
TARGET_SERVER.stubFor(get("/server-error").willReturn(aResponse().withStatus(HttpStatus.SC_SERVER_ERROR)));
4443

45-
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(),
44+
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT,
4645
URI.create(TARGET_SERVER.url("/client-error")))).isInstanceOf(IOException.class);
47-
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(),
46+
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT,
4847
URI.create(TARGET_SERVER.url("/not-found")))).isInstanceOf(IOException.class);
49-
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(),
48+
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT,
5049
URI.create(TARGET_SERVER.url("/unauthorized")))).isInstanceOf(IOException.class);
51-
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(),
50+
assertThatThrownBy(() -> endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT,
5251
URI.create(TARGET_SERVER.url("/server-error")))).isInstanceOf(IOException.class);
5352

5453
}

client/src/test/java/dev/rilling/webmention4j/client/internal/EndpointDiscoveryServiceSpecIT.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
44
import dev.rilling.webmention4j.client.internal.link.HeaderLinkParser;
55
import dev.rilling.webmention4j.client.internal.link.HtmlLinkParser;
6-
import dev.rilling.webmention4j.common.test.AutoClosableExtension;
76
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
87
import org.apache.hc.client5.http.impl.classic.HttpClients;
98
import org.apache.hc.core5.http.ContentType;
109
import org.apache.hc.core5.http.HttpHeaders;
10+
import org.junit.jupiter.api.AutoClose;
1111
import org.junit.jupiter.api.DisplayName;
1212
import org.junit.jupiter.api.Tag;
1313
import org.junit.jupiter.api.Test;
@@ -29,9 +29,8 @@ class EndpointDiscoveryServiceSpecIT {
2929
.options(wireMockConfig().dynamicPort())
3030
.build();
3131

32-
@RegisterExtension
33-
static final AutoClosableExtension<CloseableHttpClient> HTTP_CLIENT_EXTENSION = new AutoClosableExtension<>(
34-
HttpClients::createDefault);
32+
@AutoClose
33+
static final CloseableHttpClient HTTP_CLIENT = HttpClients.createDefault();
3534

3635
final EndpointDiscoveryService endpointDiscoveryService = new EndpointDiscoveryService(new HeaderLinkParser(),
3736
new HtmlLinkParser());
@@ -45,7 +44,7 @@ void followsRedirects() throws IOException {
4544
"<http://aaronpk.example/webmention-endpoint>; rel=\"webmention\"")));
4645

4746
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron-redirect"));
48-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
47+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
4948
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint"));
5049

5150
}
@@ -57,7 +56,7 @@ void usesLinkHeader() throws IOException {
5756
"<http://aaronpk.example/webmention-endpoint>; rel=\"webmention\"")));
5857

5958
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
60-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
59+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
6160
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint"));
6261

6362
}
@@ -78,7 +77,7 @@ void usesLinkHtmlElement() throws IOException {
7877
</html>""")));
7978

8079
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
81-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
80+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
8281
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint"));
8382

8483
}
@@ -99,7 +98,7 @@ void usesAnchorHtmlElement() throws IOException {
9998
</html>""")));
10099

101100
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
102-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
101+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
103102
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint"));
104103

105104
}
@@ -125,7 +124,7 @@ void prioritizesHeader() throws IOException {
125124
</html>""")));
126125

127126
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
128-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
127+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
129128
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint1"));
130129

131130
}
@@ -149,7 +148,7 @@ void prioritizesFirstElement() throws IOException {
149148
</html>""")));
150149

151150
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
152-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
151+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
153152
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint1"));
154153

155154
}
@@ -163,7 +162,7 @@ void adaptsRelativeUriForHeader() throws IOException {
163162

164163
URI targetUri = URI.create(TARGET_SERVER.url("/blog/post-by-aaron"));
165164

166-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
165+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
167166
assertThat(endpoint).contains(URI.create(TARGET_SERVER.url("/webmention-endpoint")));
168167

169168
}
@@ -184,7 +183,7 @@ void adaptsRelativeUriForElement() throws IOException {
184183
</html>""")));
185184

186185
URI targetUri = URI.create(TARGET_SERVER.url("/blog/post-by-aaron"));
187-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
186+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
188187
assertThat(endpoint).contains(URI.create(TARGET_SERVER.url("/webmention-endpoint")));
189188

190189
}
@@ -197,7 +196,7 @@ void preservesQueryParamsForHeader() throws IOException {
197196
"<http://aaronpk.example/webmention-endpoint?version=1>; rel=\"webmention\"")));
198197

199198
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
200-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
199+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
201200
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint?version=1"));
202201

203202
}
@@ -218,7 +217,7 @@ void preservesQueryParamsForElement() throws IOException {
218217
</html>""")));
219218

220219
URI targetUri = URI.create(TARGET_SERVER.url("/post-by-aaron"));
221-
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT_EXTENSION.get(), targetUri);
220+
Optional<URI> endpoint = endpointDiscoveryService.discoverEndpoint(HTTP_CLIENT, targetUri);
222221
assertThat(endpoint).contains(URI.create("http://aaronpk.example/webmention-endpoint?version=1"));
223222
}
224223
}

client/src/test/java/dev/rilling/webmention4j/client/internal/EndpointServiceIT.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
44
import dev.rilling.webmention4j.common.Webmention;
5-
import dev.rilling.webmention4j.common.test.AutoClosableExtension;
65
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
76
import org.apache.hc.client5.http.impl.classic.HttpClients;
87
import org.apache.hc.core5.http.HttpHeaders;
98
import org.apache.hc.core5.http.HttpStatus;
9+
import org.junit.jupiter.api.AutoClose;
1010
import org.junit.jupiter.api.DisplayName;
1111
import org.junit.jupiter.api.Test;
1212
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -26,9 +26,8 @@ class EndpointServiceIT {
2626
.options(wireMockConfig().dynamicPort())
2727
.build();
2828

29-
@RegisterExtension
30-
static final AutoClosableExtension<CloseableHttpClient> HTTP_CLIENT_EXTENSION = new AutoClosableExtension<>(
31-
HttpClients::createDefault);
29+
@AutoClose
30+
static final CloseableHttpClient HTTP_CLIENT = HttpClients.createDefault();
3231

3332
final EndpointService endpointService = new EndpointService();
3433

@@ -41,7 +40,7 @@ void throwsForInvalidLocationHeader() {
4140
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
4241
URI target = URI.create("https://aaronpk.example/post-by-aaron");
4342

44-
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
43+
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT,
4544
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint")),
4645
new Webmention(source, target))).isInstanceOf(IOException.class);
4746
}

client/src/test/java/dev/rilling/webmention4j/client/internal/EndpointServiceSpecIT.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
66
import com.github.tomakehurst.wiremock.matching.UrlPattern;
77
import dev.rilling.webmention4j.common.Webmention;
8-
import dev.rilling.webmention4j.common.test.AutoClosableExtension;
98
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
109
import org.apache.hc.client5.http.impl.classic.HttpClients;
1110
import org.apache.hc.core5.http.HttpHeaders;
1211
import org.apache.hc.core5.http.HttpStatus;
12+
import org.junit.jupiter.api.AutoClose;
1313
import org.junit.jupiter.api.DisplayName;
1414
import org.junit.jupiter.api.Tag;
1515
import org.junit.jupiter.api.Test;
@@ -32,9 +32,8 @@ class EndpointServiceSpecIT {
3232
.options(wireMockConfig().dynamicPort())
3333
.build();
3434

35-
@RegisterExtension
36-
static final AutoClosableExtension<CloseableHttpClient> HTTP_CLIENT_EXTENSION = new AutoClosableExtension<>(
37-
HttpClients::createDefault);
35+
@AutoClose
36+
static final CloseableHttpClient HTTP_CLIENT = HttpClients.createDefault();
3837

3938
final EndpointService endpointService = new EndpointService();
4039

@@ -48,7 +47,7 @@ void sendsEncodedData() throws IOException {
4847
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
4948
URI target = URI.create("https://aaronpk.example/post-by-aaron");
5049

51-
endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(), endpoint, new Webmention(source, target));
50+
endpointService.notifyEndpoint(HTTP_CLIENT, endpoint, new Webmention(source, target));
5251

5352
UrlPattern urlPattern = new UrlPattern(new EqualToPattern("/webmention-endpoint", false), false);
5453
EqualToPattern contentTypePattern = new EqualToPattern("application/x-www-form-urlencoded; charset=UTF-8");
@@ -68,7 +67,7 @@ void keepsQueryParams() throws IOException {
6867
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
6968
URI target = URI.create("https://aaronpk.example/post-by-aaron");
7069

71-
endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(), endpoint, new Webmention(source, target));
70+
endpointService.notifyEndpoint(HTTP_CLIENT, endpoint, new Webmention(source, target));
7271

7372
UrlPattern urlPattern = new UrlPattern(new EqualToPattern("/webmention-endpoint?version=1", false), false);
7473
EqualToPattern bodyPattern = new EqualToPattern("source=https%3A%2F%2Fwaterpigs.example%2Fpost-by-barnaby" +
@@ -86,7 +85,7 @@ void returnsMonitoringUrlFor201() throws IOException {
8685
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
8786
URI target = URI.create("https://aaronpk.example/post-by-aaron");
8887

89-
assertThat(endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
88+
assertThat(endpointService.notifyEndpoint(HTTP_CLIENT,
9089
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint")),
9190
new Webmention(source, target))).contains(URI.create("https://example.com/monitoring"));
9291
}
@@ -101,7 +100,7 @@ void returnsNoMonitoringUrlForOthers() throws IOException {
101100
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
102101
URI target = URI.create("https://aaronpk.example/post-by-aaron");
103102

104-
assertThat(endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
103+
assertThat(endpointService.notifyEndpoint(HTTP_CLIENT,
105104
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint")),
106105
new Webmention(source, target))).isEmpty();
107106
}
@@ -116,13 +115,13 @@ void allows2XXStatus() throws IOException {
116115
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
117116
URI target = URI.create("https://aaronpk.example/post-by-aaron");
118117

119-
endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
118+
endpointService.notifyEndpoint(HTTP_CLIENT,
120119
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-ok")),
121120
new Webmention(source, target));
122-
endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
121+
endpointService.notifyEndpoint(HTTP_CLIENT,
123122
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-created")),
124123
new Webmention(source, target));
125-
endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
124+
endpointService.notifyEndpoint(HTTP_CLIENT,
126125
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-accepted")),
127126
new Webmention(source, target));
128127
}
@@ -138,16 +137,16 @@ void throwsForNon2XXStatus() {
138137
URI source = URI.create("https://waterpigs.example/post-by-barnaby");
139138
URI target = URI.create("https://aaronpk.example/post-by-aaron");
140139

141-
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
140+
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT,
142141
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-client")),
143142
new Webmention(source, target))).isInstanceOf(IOException.class);
144-
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
143+
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT,
145144
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-unauthorized")),
146145
new Webmention(source, target))).isInstanceOf(IOException.class);
147-
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
146+
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT,
148147
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-not-found")),
149148
new Webmention(source, target))).isInstanceOf(IOException.class);
150-
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT_EXTENSION.get(),
149+
assertThatThrownBy(() -> endpointService.notifyEndpoint(HTTP_CLIENT,
151150
URI.create(ENDPOINT_SERVER.url("/webmention-endpoint-server-error")),
152151
new Webmention(source, target))).isInstanceOf(IOException.class);
153152
}

common-test/pom.xml

-24
This file was deleted.

common-test/src/main/java/dev/rilling/webmention4j/common/test/AutoClosableExtension.java

-30
This file was deleted.

pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
<modules>
1414
<module>common</module>
15-
<module>common-test</module>
1615
<module>client</module>
1716
<module>server</module>
1817
<module>example</module>

server/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
<version>5.0.0</version>
4848
</dependency>
4949

50-
<dependency>
51-
<groupId>dev.rilling</groupId>
52-
<artifactId>webmention4j-common-test</artifactId>
53-
<version>${project.version}</version>
54-
<scope>test</scope>
55-
</dependency>
5650
<dependency>
5751
<groupId>org.junit.jupiter</groupId>
5852
<artifactId>junit-jupiter-api</artifactId>

0 commit comments

Comments
 (0)