Skip to content

Commit cfafcc5

Browse files
author
eugenp
committed
cleanup work
1 parent 6633f5b commit cfafcc5

4 files changed

Lines changed: 89 additions & 10 deletions

File tree

core-java/src/test/java/org/baeldung/java/CoreJavaUnitTest.java renamed to core-java/src/test/java/org/baeldung/java/CoreJavaCollectionsUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import com.google.common.collect.ImmutableList;
1212

13-
public class CoreJavaUnitTest {
13+
public class CoreJavaCollectionsUnitTest {
1414

1515
// tests -
1616

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.baeldung.java;
2+
3+
import org.junit.Test;
4+
5+
public class CoreJavaIoUnitTest {
6+
7+
// tests -
8+
9+
@Test
10+
public final void whenIteratingAFile_thenCorrect() {
11+
//
12+
}
13+
14+
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.http.client.ClientProtocolException;
1313
import org.apache.http.client.methods.CloseableHttpResponse;
1414
import org.apache.http.client.methods.HttpGet;
15-
import org.apache.http.client.methods.HttpPost;
1615
import org.apache.http.entity.ContentType;
1716
import org.apache.http.impl.client.CloseableHttpClient;
1817
import org.apache.http.impl.client.HttpClientBuilder;
@@ -63,7 +62,7 @@ public final void whenExecutingBasicGetRequest_thenNoExceptions() throws ClientP
6362
@Test
6463
public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectStatusCode() throws ClientProtocolException, IOException {
6564
response = instance.execute(new HttpGet(SAMPLE_URL));
66-
int statusCode = response.getStatusLine().getStatusCode();
65+
final int statusCode = response.getStatusLine().getStatusCode();
6766
assertThat(statusCode, equalTo(HttpStatus.SC_OK));
6867
}
6968

@@ -83,11 +82,4 @@ public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectBo
8382
assertThat(bodyAsString, notNullValue());
8483
}
8584

86-
// tests - non-GET
87-
88-
@Test
89-
public final void whenExecutingBasicRequest_thenNoExceptions() throws ClientProtocolException, IOException {
90-
instance.execute(new HttpPost(SAMPLE_URL));
91-
}
92-
9385
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.baeldung.httpclient;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
import org.apache.http.HttpEntity;
7+
import org.apache.http.auth.AuthenticationException;
8+
import org.apache.http.auth.UsernamePasswordCredentials;
9+
import org.apache.http.client.ClientProtocolException;
10+
import org.apache.http.client.methods.CloseableHttpResponse;
11+
import org.apache.http.client.methods.HttpPost;
12+
import org.apache.http.entity.StringEntity;
13+
import org.apache.http.impl.auth.BasicScheme;
14+
import org.apache.http.impl.client.CloseableHttpClient;
15+
import org.apache.http.impl.client.HttpClientBuilder;
16+
import org.junit.After;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
20+
public class HttpClientBasicPostLiveTest {
21+
22+
private static final String SAMPLE_URL = "http://www.github.com";
23+
24+
private CloseableHttpClient instance;
25+
26+
private CloseableHttpResponse response;
27+
28+
@Before
29+
public final void before() {
30+
instance = HttpClientBuilder.create().build();
31+
}
32+
33+
@After
34+
public final void after() throws IllegalStateException, IOException {
35+
if (response == null) {
36+
return;
37+
}
38+
39+
try {
40+
final HttpEntity entity = response.getEntity();
41+
if (entity != null) {
42+
final InputStream instream = entity.getContent();
43+
instream.close();
44+
}
45+
} finally {
46+
response.close();
47+
}
48+
}
49+
50+
// tests - non-GET
51+
52+
@Test
53+
public final void whenExecutingPostRequest_thenNoExceptions() throws ClientProtocolException, IOException {
54+
instance.execute(new HttpPost(SAMPLE_URL));
55+
}
56+
57+
@Test
58+
public final void whenExecutingPostRequestWithBody_thenNoExceptions() throws ClientProtocolException, IOException {
59+
final HttpPost request = new HttpPost(SAMPLE_URL);
60+
request.setEntity(new StringEntity("in the body of the POST"));
61+
instance.execute(request);
62+
}
63+
64+
@Test
65+
public final void givenAuth_whenExecutingPostRequestWithBody_thenNoExceptions() throws ClientProtocolException, IOException, AuthenticationException {
66+
final HttpPost request = new HttpPost(SAMPLE_URL);
67+
request.setEntity(new StringEntity("in the body of the POST"));
68+
final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("username", "password");
69+
request.addHeader(new BasicScheme().authenticate(creds, request, null));
70+
instance.execute(request);
71+
}
72+
73+
}

0 commit comments

Comments
 (0)