Skip to content

Commit dee8750

Browse files
committed
Stop Jetty in Jetty8JettyEmbeddedServletContainerFactoryTests
Closes gh-12734
1 parent edc00ee commit dee8750

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/Jetty8JettyEmbeddedServletContainerFactoryTests.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,23 +70,28 @@ public void onStartup(ServletContext servletContext)
7070

7171
});
7272
jetty.start();
73-
int port = jetty.getPort();
74-
RestTemplate restTemplate = new RestTemplate();
75-
restTemplate.setErrorHandler(new ResponseErrorHandler() {
76-
77-
@Override
78-
public boolean hasError(ClientHttpResponse response) throws IOException {
79-
return false;
80-
}
81-
82-
@Override
83-
public void handleError(ClientHttpResponse response) throws IOException {
84-
}
85-
86-
});
87-
ResponseEntity<String> response = restTemplate
88-
.getForEntity("http://localhost:" + port, String.class);
89-
assertThat(response.getBody()).isEqualTo("An error occurred");
73+
try {
74+
int port = jetty.getPort();
75+
RestTemplate restTemplate = new RestTemplate();
76+
restTemplate.setErrorHandler(new ResponseErrorHandler() {
77+
78+
@Override
79+
public boolean hasError(ClientHttpResponse response) throws IOException {
80+
return false;
81+
}
82+
83+
@Override
84+
public void handleError(ClientHttpResponse response) throws IOException {
85+
}
86+
87+
});
88+
ResponseEntity<String> response = restTemplate
89+
.getForEntity("http://localhost:" + port, String.class);
90+
assertThat(response.getBody()).isEqualTo("An error occurred");
91+
}
92+
finally {
93+
jetty.stop();
94+
}
9095
}
9196

9297
private static final class TestServlet extends HttpServlet {

0 commit comments

Comments
 (0)