Skip to content

Commit c1f94aa

Browse files
author
James Kerak
committed
fixing incorrect merge
1 parent 7e5bea3 commit c1f94aa

5 files changed

Lines changed: 8 additions & 40 deletions

File tree

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ public class OkHttpFileUploadingLiveTest {
2727

2828
@Before
2929
public void init() {
30-
3130
client = new OkHttpClient();
3231
}
3332

3433
@Test
3534
public void whenUploadFile_thenCorrect() throws IOException {
3635

37-
client = new OkHttpClient();
38-
3936
RequestBody requestBody = new MultipartBody.Builder()
4037
.setType(MultipartBody.FORM)
4138
.addFormDataPart("file", "file.txt",
@@ -56,8 +53,6 @@ public void whenUploadFile_thenCorrect() throws IOException {
5653
@Test
5754
public void whenGetUploadFileProgress_thenCorrect() throws IOException {
5855

59-
client = new OkHttpClient();
60-
6156
RequestBody requestBody = new MultipartBody.Builder()
6257
.setType(MultipartBody.FORM)
6358
.addFormDataPart("file", "file.txt",

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import okhttp3.Request;
1414
import okhttp3.Response;
1515

16+
1617
public class OkHttpGetLiveTest {
1718

1819
private static final String BASE_URL = "http://localhost:8080/spring-rest";
@@ -27,9 +28,6 @@ public void init() {
2728

2829
@Test
2930
public void whenGetRequest_thenCorrect() throws IOException {
30-
31-
client = new OkHttpClient();
32-
3331
Request request = new Request.Builder()
3432
.url(BASE_URL + "/date")
3533
.build();
@@ -42,9 +40,6 @@ public void whenGetRequest_thenCorrect() throws IOException {
4240

4341
@Test
4442
public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
45-
46-
client = new OkHttpClient();
47-
4843
HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder();
4944
urlBuilder.addQueryParameter("id", "1");
5045

@@ -62,9 +57,6 @@ public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
6257

6358
@Test
6459
public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException {
65-
66-
client = new OkHttpClient();
67-
6860
Request request = new Request.Builder()
6961
.url(BASE_URL + "/date")
7062
.build();

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderLiveTest.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public void init() {
2424

2525
@Test
2626
public void whenSetHeader_thenCorrect() throws IOException {
27-
28-
client = new OkHttpClient();
29-
3027
Request request = new Request.Builder()
3128
.url(SAMPLE_URL)
3229
.addHeader("Content-Type", "application/json")
@@ -40,15 +37,15 @@ public void whenSetHeader_thenCorrect() throws IOException {
4037
@Test
4138
public void whenSetDefaultHeader_thenCorrect() throws IOException {
4239

43-
OkHttpClient client = new OkHttpClient.Builder()
40+
OkHttpClient clientWithInterceptor = new OkHttpClient.Builder()
4441
.addInterceptor(new DefaultContentTypeInterceptor("application/json"))
4542
.build();
4643

4744
Request request = new Request.Builder()
4845
.url(SAMPLE_URL)
4946
.build();
5047

51-
Call call = client.newCall(request);
48+
Call call = clientWithInterceptor.newCall(request);
5249
Response response = call.execute();
5350
response.close();
5451
}

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,23 @@ public void init() {
3434

3535
@Test
3636
public void whenSetRequestTimeout_thenFail() throws IOException {
37-
38-
OkHttpClient client = new OkHttpClient.Builder()
37+
OkHttpClient clientWithTimeout = new OkHttpClient.Builder()
3938
.readTimeout(1, TimeUnit.SECONDS)
4039
.build();
4140

4241
Request request = new Request.Builder()
4342
.url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay.
4443
.build();
4544

46-
Call call = client.newCall(request);
45+
Call call = clientWithTimeout.newCall(request);
4746
Response response = call.execute();
4847
response.close();
4948
}
5049

5150
@Test(expected = IOException.class)
5251
public void whenCancelRequest_thenCorrect() throws IOException {
53-
5452
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
5553

56-
client = new OkHttpClient();
57-
5854
Request request = new Request.Builder()
5955
.url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay.
6056
.build();
@@ -85,18 +81,18 @@ public void whenSetResponseCache_thenCorrect() throws IOException {
8581
File cacheDirectory = new File("src/test/resources/cache");
8682
Cache cache = new Cache(cacheDirectory, cacheSize);
8783

88-
OkHttpClient client = new OkHttpClient.Builder()
84+
OkHttpClient clientCached = new OkHttpClient.Builder()
8985
.cache(cache)
9086
.build();
9187

9288
Request request = new Request.Builder()
9389
.url("http://publicobject.com/helloworld.txt")
9490
.build();
9591

96-
Response response1 = client.newCall(request).execute();
92+
Response response1 = clientCached.newCall(request).execute();
9793
logResponse(response1);
9894

99-
Response response2 = client.newCall(request).execute();
95+
Response response2 = clientCached.newCall(request).execute();
10096
logResponse(response2);
10197
}
10298

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public void init() {
3434

3535
@Test
3636
public void whenSendPostRequest_thenCorrect() throws IOException {
37-
38-
client = new OkHttpClient();
39-
4037
RequestBody formBody = new FormBody.Builder()
4138
.add("username", "test")
4239
.add("password", "test")
@@ -55,11 +52,8 @@ public void whenSendPostRequest_thenCorrect() throws IOException {
5552

5653
@Test
5754
public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException {
58-
5955
String postBody = "test post";
6056

61-
client = new OkHttpClient();
62-
6357
Request request = new Request.Builder()
6458
.url(URL_SECURED_BY_BASIC_AUTHENTICATION)
6559
.addHeader("Authorization", Credentials.basic("test", "test"))
@@ -74,9 +68,6 @@ public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOExceptio
7468

7569
@Test
7670
public void whenPostJson_thenCorrect() throws IOException {
77-
78-
client = new OkHttpClient();
79-
8071
String json = "{\"id\":1,\"name\":\"John\"}";
8172

8273
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
@@ -94,9 +85,6 @@ public void whenPostJson_thenCorrect() throws IOException {
9485

9586
@Test
9687
public void whenSendMultipartRequest_thenCorrect() throws IOException {
97-
98-
client = new OkHttpClient();
99-
10088
RequestBody requestBody = new MultipartBody.Builder()
10189
.setType(MultipartBody.FORM)
10290
.addFormDataPart("username", "test")

0 commit comments

Comments
 (0)