Skip to content

Commit 7e5bea3

Browse files
author
James Kerak
committed
resolving merge conflict
2 parents 2186f64 + 4d4afa6 commit 7e5bea3

5 files changed

Lines changed: 74 additions & 24 deletions

File tree

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99

1010
import org.baeldung.okhttp.ProgressRequestWrapper;
11+
import org.junit.Before;
1112
import org.junit.Test;
1213

1314
import okhttp3.Call;
@@ -22,10 +23,18 @@ public class OkHttpFileUploadingLiveTest {
2223

2324
private static final String BASE_URL = "http://localhost:8080/spring-rest";
2425

26+
OkHttpClient client;
27+
28+
@Before
29+
public void init() {
30+
31+
client = new OkHttpClient();
32+
}
33+
2534
@Test
2635
public void whenUploadFile_thenCorrect() throws IOException {
2736

28-
OkHttpClient client = new OkHttpClient();
37+
client = new OkHttpClient();
2938

3039
RequestBody requestBody = new MultipartBody.Builder()
3140
.setType(MultipartBody.FORM)
@@ -47,22 +56,19 @@ public void whenUploadFile_thenCorrect() throws IOException {
4756
@Test
4857
public void whenGetUploadFileProgress_thenCorrect() throws IOException {
4958

50-
OkHttpClient client = new OkHttpClient();
59+
client = new OkHttpClient();
5160

5261
RequestBody requestBody = new MultipartBody.Builder()
5362
.setType(MultipartBody.FORM)
5463
.addFormDataPart("file", "file.txt",
5564
RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt")))
5665
.build();
5766

67+
ProgressRequestWrapper countingBody = new ProgressRequestWrapper(requestBody, (long bytesWritten, long contentLength) -> {
5868

59-
ProgressRequestWrapper.ProgressListener listener = (bytesWritten, contentLength) -> {
60-
61-
float percentage = 100f * bytesWritten / contentLength;
69+
float percentage = 100f * bytesWritten / contentLength;
6270
assertFalse(Float.compare(percentage, 100) > 0);
63-
};
64-
65-
ProgressRequestWrapper countingBody = new ProgressRequestWrapper(requestBody, listener);
71+
});
6672

6773
Request request = new Request.Builder()
6874
.url(BASE_URL + "/users/upload")

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@
44
import org.junit.Test;
55

66
import java.io.IOException;
7-
8-
import static org.hamcrest.Matchers.equalTo;
9-
import static org.junit.Assert.assertThat;
10-
import static org.junit.Assert.fail;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import okhttp3.Call;
10+
import okhttp3.Callback;
11+
import okhttp3.HttpUrl;
12+
import okhttp3.OkHttpClient;
13+
import okhttp3.Request;
14+
import okhttp3.Response;
1115

1216
public class OkHttpGetLiveTest {
1317

1418
private static final String BASE_URL = "http://localhost:8080/spring-rest";
1519

20+
OkHttpClient client;
21+
22+
@Before
23+
public void init() {
24+
25+
client = new OkHttpClient();
26+
}
27+
1628
@Test
1729
public void whenGetRequest_thenCorrect() throws IOException {
1830

19-
OkHttpClient client = new OkHttpClient();
31+
client = new OkHttpClient();
2032

2133
Request request = new Request.Builder()
2234
.url(BASE_URL + "/date")
@@ -31,7 +43,7 @@ public void whenGetRequest_thenCorrect() throws IOException {
3143
@Test
3244
public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
3345

34-
OkHttpClient client = new OkHttpClient();
46+
client = new OkHttpClient();
3547

3648
HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder();
3749
urlBuilder.addQueryParameter("id", "1");
@@ -51,7 +63,7 @@ public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
5163
@Test
5264
public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException {
5365

54-
OkHttpClient client = new OkHttpClient();
66+
client = new OkHttpClient();
5567

5668
Request request = new Request.Builder()
5769
.url(BASE_URL + "/date")

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44

5+
import org.junit.Before;
56
import org.junit.Test;
67

78
import okhttp3.Call;
@@ -13,10 +14,18 @@ public class OkHttpHeaderLiveTest {
1314

1415
private static final String SAMPLE_URL = "http://www.github.com";
1516

17+
OkHttpClient client;
18+
19+
@Before
20+
public void init() {
21+
22+
client = new OkHttpClient();
23+
}
24+
1625
@Test
1726
public void whenSetHeader_thenCorrect() throws IOException {
1827

19-
OkHttpClient client = new OkHttpClient();
28+
client = new OkHttpClient();
2029

2130
Request request = new Request.Builder()
2231
.url(SAMPLE_URL)
@@ -43,6 +52,4 @@ public void whenSetDefaultHeader_thenCorrect() throws IOException {
4352
Response response = call.execute();
4453
response.close();
4554
}
46-
47-
4855
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@
44
import org.junit.Test;
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
7-
87
import java.io.File;
98
import java.io.IOException;
109
import java.util.concurrent.Executors;
1110
import java.util.concurrent.ScheduledExecutorService;
1211
import java.util.concurrent.TimeUnit;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
import okhttp3.Cache;
17+
import okhttp3.Call;
18+
import okhttp3.OkHttpClient;
19+
import okhttp3.Request;
20+
import okhttp3.Response;
1321

1422
public class OkHttpMiscLiveTest {
1523

1624
private static final String BASE_URL = "http://localhost:8080/spring-rest";
1725
private static Logger logger = LoggerFactory.getLogger(OkHttpMiscLiveTest.class);
1826

27+
OkHttpClient client;
28+
29+
@Before
30+
public void init() {
31+
32+
client = new OkHttpClient();
33+
}
34+
1935
@Test
2036
public void whenSetRequestTimeout_thenFail() throws IOException {
2137

@@ -37,7 +53,7 @@ public void whenCancelRequest_thenCorrect() throws IOException {
3753

3854
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
3955

40-
OkHttpClient client = new OkHttpClient();
56+
client = new OkHttpClient();
4157

4258
Request request = new Request.Builder()
4359
.url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay.

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.io.IOException;
88

9+
import org.junit.Before;
910
import org.junit.Test;
1011

1112
import okhttp3.Call;
@@ -23,10 +24,18 @@ public class OkHttpPostingLiveTest {
2324
private static final String BASE_URL = "http://localhost:8080/spring-rest";
2425
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
2526

27+
OkHttpClient client;
28+
29+
@Before
30+
public void init() {
31+
32+
client = new OkHttpClient();
33+
}
34+
2635
@Test
2736
public void whenSendPostRequest_thenCorrect() throws IOException {
2837

29-
OkHttpClient client = new OkHttpClient();
38+
client = new OkHttpClient();
3039

3140
RequestBody formBody = new FormBody.Builder()
3241
.add("username", "test")
@@ -49,7 +58,7 @@ public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOExceptio
4958

5059
String postBody = "test post";
5160

52-
OkHttpClient client = new OkHttpClient();
61+
client = new OkHttpClient();
5362

5463
Request request = new Request.Builder()
5564
.url(URL_SECURED_BY_BASIC_AUTHENTICATION)
@@ -66,7 +75,7 @@ public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOExceptio
6675
@Test
6776
public void whenPostJson_thenCorrect() throws IOException {
6877

69-
OkHttpClient client = new OkHttpClient();
78+
client = new OkHttpClient();
7079

7180
String json = "{\"id\":1,\"name\":\"John\"}";
7281

@@ -86,7 +95,7 @@ public void whenPostJson_thenCorrect() throws IOException {
8695
@Test
8796
public void whenSendMultipartRequest_thenCorrect() throws IOException {
8897

89-
OkHttpClient client = new OkHttpClient();
98+
client = new OkHttpClient();
9099

91100
RequestBody requestBody = new MultipartBody.Builder()
92101
.setType(MultipartBody.FORM)

0 commit comments

Comments
 (0)