|
1 | 1 | package org.jruby.warbler; |
2 | 2 |
|
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
3 | 5 | import java.net.*; |
4 | 6 | import java.io.*; |
5 | | -import org.junit.Assert; |
6 | | -import org.junit.Test; |
7 | | -import org.hamcrest.Matcher; |
8 | | -import org.hamcrest.Matchers; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 9 | + |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Unit test for simple App. |
12 | 13 | */ |
13 | | -public class AppTestIT |
14 | | -{ |
15 | | - private static String appName = "simple_rack_test-1.0"; |
16 | | - |
| 14 | +public class AppTestIT { |
17 | 15 | /** |
18 | 16 | * Hit the web app and test the response |
19 | 17 | */ |
20 | 18 | @Test |
21 | | - public void testApp() throws Exception |
22 | | - { |
23 | | - URL url = new URL("http://localhost:8080/" + appName); |
24 | | - URLConnection conn = url.openConnection(); |
25 | | - BufferedReader in = new BufferedReader( new InputStreamReader( conn.getInputStream())); |
26 | | - |
27 | | - String inputLine; |
28 | | - String content = ""; |
29 | | - |
30 | | - while ((inputLine = in.readLine()) != null) |
31 | | - content = inputLine; |
32 | | - in.close(); |
| 19 | + public void testApp() throws Exception { |
| 20 | + assertEquals("Hello, World", contentFrom("http://localhost:8080/")); |
| 21 | + } |
33 | 22 |
|
34 | | - Assert.assertEquals("Hello, World", content); |
| 23 | + private static String contentFrom(@SuppressWarnings("SameParameterValue") String url) throws IOException { |
| 24 | + URL route = new URL(url); |
| 25 | + StringBuilder content = new StringBuilder(); |
| 26 | + try (BufferedReader in = new BufferedReader(new InputStreamReader(route.openStream()))) { |
| 27 | + while (in.ready()) { |
| 28 | + content.append(in.readLine()); |
| 29 | + } |
| 30 | + } |
| 31 | + return content.toString(); |
35 | 32 | } |
36 | 33 | } |
0 commit comments