1010import java .io .IOException ;
1111import java .io .InputStream ;
1212import java .io .InputStreamReader ;
13+ import java .net .URL ;
1314
1415import org .apache .http .HttpEntity ;
1516import 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
0 commit comments