diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java index 0f40f2236f..4e183c0150 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java @@ -10,6 +10,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; @@ -39,7 +40,7 @@ public class HttpClientMultipartTest { private CloseableHttpResponse response; @Before - public final void Before() { + public final void before() { client = HttpClientBuilder.create().build(); post = new HttpPost(SERVER); textFileName = "temp.txt"; @@ -53,13 +54,11 @@ public class HttpClientMultipartTest { try { client.close(); } catch (final IOException e1) { - e1.printStackTrace(); } try { rd.close(); } catch (final IOException e) { - e.printStackTrace(); } try { @@ -73,9 +72,12 @@ public class HttpClientMultipartTest { } } + // tests + @Test public final void givenFileandMultipleTextParts_whenUploadwithAddPart_thenNoExceptions() throws IOException { - final File file = new File(textFileName); + final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName); + final File file = new File(url.getPath()); final FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY); final StringBody stringBody1 = new StringBody("This is message 1", ContentType.MULTIPART_FORM_DATA); final StringBody stringBody2 = new StringBody("This is message 2", ContentType.MULTIPART_FORM_DATA); @@ -163,7 +165,9 @@ public class HttpClientMultipartTest { System.out.println("POST Content Type: " + contentTypeInHeader); } - public String getContent() throws IOException { + // UTIL + + final String getContent() throws IOException { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String body = ""; String content = ""; @@ -173,7 +177,7 @@ public class HttpClientMultipartTest { return content.trim(); } - public String getContentTypeHeader() throws IOException { + final String getContentTypeHeader() throws IOException { return post.getEntity().getContentType().toString(); } diff --git a/httpclient/image.jpg b/httpclient/src/test/resources/uploads/image.jpg similarity index 100% rename from httpclient/image.jpg rename to httpclient/src/test/resources/uploads/image.jpg diff --git a/httpclient/src/test/resources/sandbox.txt b/httpclient/src/test/resources/uploads/sandbox.txt similarity index 100% rename from httpclient/src/test/resources/sandbox.txt rename to httpclient/src/test/resources/uploads/sandbox.txt diff --git a/httpclient/temp.txt b/httpclient/src/test/resources/uploads/temp.txt similarity index 100% rename from httpclient/temp.txt rename to httpclient/src/test/resources/uploads/temp.txt diff --git a/httpclient/zipFile.zip b/httpclient/src/test/resources/uploads/zipFile.zip similarity index 100% rename from httpclient/zipFile.zip rename to httpclient/src/test/resources/uploads/zipFile.zip