Skip to content

Commit 83ccbf0

Browse files
author
eugenp
committed
httpclient cleanup work
1 parent 1928140 commit 83ccbf0

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.IOException;
1111
import java.io.InputStream;
1212
import java.io.InputStreamReader;
13+
import java.net.URL;
1314

1415
import org.apache.http.HttpEntity;
1516
import org.apache.http.HttpStatus;
@@ -39,7 +40,7 @@ public class HttpClientMultipartTest {
3940
private CloseableHttpResponse response;
4041

4142
@Before
42-
public final void Before() {
43+
public final void before() {
4344
client = HttpClientBuilder.create().build();
4445
post = new HttpPost(SERVER);
4546
textFileName = "temp.txt";
@@ -53,13 +54,11 @@ public final void after() throws IllegalStateException, IOException {
5354
try {
5455
client.close();
5556
} catch (final IOException e1) {
56-
5757
e1.printStackTrace();
5858
}
5959
try {
6060
rd.close();
6161
} catch (final IOException e) {
62-
6362
e.printStackTrace();
6463
}
6564
try {
@@ -73,9 +72,12 @@ public final void after() throws IllegalStateException, IOException {
7372
}
7473
}
7574

75+
// tests
76+
7677
@Test
7778
public final void givenFileandMultipleTextParts_whenUploadwithAddPart_thenNoExceptions() throws IOException {
78-
final File file = new File(textFileName);
79+
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName);
80+
final File file = new File(url.getPath());
7981
final FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
8082
final StringBody stringBody1 = new StringBody("This is message 1", ContentType.MULTIPART_FORM_DATA);
8183
final StringBody stringBody2 = new StringBody("This is message 2", ContentType.MULTIPART_FORM_DATA);
@@ -163,7 +165,9 @@ public final void givenCharArrayandText_whenUploadwithAddBinaryBodyandAddTextBod
163165
System.out.println("POST Content Type: " + contentTypeInHeader);
164166
}
165167

166-
public String getContent() throws IOException {
168+
// UTIL
169+
170+
final String getContent() throws IOException {
167171
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
168172
String body = "";
169173
String content = "";
@@ -173,7 +177,7 @@ public String getContent() throws IOException {
173177
return content.trim();
174178
}
175179

176-
public String getContentTypeHeader() throws IOException {
180+
final String getContentTypeHeader() throws IOException {
177181
return post.getEntity().getContentType().toString();
178182
}
179183

httpclient/image.jpg renamed to httpclient/src/test/resources/uploads/image.jpg

File renamed without changes.
File renamed without changes.

httpclient/temp.txt renamed to httpclient/src/test/resources/uploads/temp.txt

File renamed without changes.

httpclient/zipFile.zip renamed to httpclient/src/test/resources/uploads/zipFile.zip

File renamed without changes.

0 commit comments

Comments
 (0)