Skip to content

Commit 84f3f4f

Browse files
committed
use at least 1 Junit38 test
1 parent 7599092 commit 84f3f4f

File tree

1 file changed

+3
-54
lines changed

1 file changed

+3
-54
lines changed

google-http-client/src/test/java/com/google/api/client/http/HttpRequestTest.java

+3-54
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414

1515
package com.google.api.client.http;
1616

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.fail;
23-
2417
import com.google.api.client.testing.http.HttpTesting;
2518
import com.google.api.client.testing.http.MockHttpTransport;
2619
import com.google.api.client.testing.http.MockHttpUnsuccessfulResponseHandler;
@@ -61,26 +54,25 @@
6154
*
6255
* @author Yaniv Inbar
6356
*/
64-
public class HttpRequestTest {
57+
public class HttpRequestTest extends TestCase {
6558

6659
private static final ImmutableSet<String> BASIC_METHODS =
6760
ImmutableSet.of(HttpMethods.GET, HttpMethods.PUT, HttpMethods.POST, HttpMethods.DELETE);
6861
private static final ImmutableSet<String> OTHER_METHODS =
6962
ImmutableSet.of(HttpMethods.HEAD, HttpMethods.PATCH);
7063

71-
@Before
64+
@Override
7265
public void setUp() {
7366
// suppress logging warnings to the console
7467
HttpTransport.LOGGER.setLevel(java.util.logging.Level.SEVERE);
7568
}
7669

77-
@After
70+
@Override
7871
public void tearDown() {
7972
// back to the standard logging level for console
8073
HttpTransport.LOGGER.setLevel(java.util.logging.Level.WARNING);
8174
}
8275

83-
@Test
8476
public void testNotSupportedByDefault() throws Exception {
8577
MockHttpTransport transport = new MockHttpTransport();
8678
HttpRequest request =
@@ -119,7 +111,6 @@ public void execute(Runnable command) {
119111
}
120112
}
121113

122-
@Deprecated
123114
private static class MockBackOffPolicy implements BackOffPolicy {
124115

125116
int backOffCalls;
@@ -211,7 +202,6 @@ public boolean handleResponse(
211202
});
212203
}
213204

214-
@Test
215205
public void test301Redirect() throws Exception {
216206
// Set up RedirectTransport to redirect on the first request and then return success.
217207
RedirectTransport fakeTransport = new RedirectTransport();
@@ -224,7 +214,6 @@ public void test301Redirect() throws Exception {
224214
}
225215

226216
@Deprecated
227-
@Test
228217
public void test301RedirectWithUnsuccessfulResponseHandled() throws Exception {
229218
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler(true);
230219
MockBackOffPolicy backOffPolicy = new MockBackOffPolicy();
@@ -248,7 +237,6 @@ public void test301RedirectWithUnsuccessfulResponseHandled() throws Exception {
248237
assertTrue(handler.isCalled());
249238
}
250239

251-
@Test
252240
public void test301RedirectWithBackOffUnsuccessfulResponseHandled() throws Exception {
253241
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler(true);
254242
// Set up RedirectTransport to redirect on the first request and then return success.
@@ -295,7 +283,6 @@ public void test301RedirectWithUnsuccessfulResponseNotHandled() throws Exception
295283
assertEquals(0, backOffPolicy.backOffCalls);
296284
}
297285

298-
@Test
299286
public void test301RedirectWithBackOffUnsuccessfulResponseNotHandled() throws Exception {
300287
// Create an Unsuccessful response handler that always returns false.
301288
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler(false);
@@ -318,7 +305,6 @@ public void test301RedirectWithBackOffUnsuccessfulResponseNotHandled() throws Ex
318305
assertEquals(0, backOff.getNumberOfTries());
319306
}
320307

321-
@Test
322308
public void test303Redirect() throws Exception {
323309
// Set up RedirectTransport to redirect on the first request and then return success.
324310
RedirectTransport fakeTransport = new RedirectTransport();
@@ -341,7 +327,6 @@ public void test303Redirect() throws Exception {
341327
assertNull(request.getContent());
342328
}
343329

344-
@Test
345330
public void testInfiniteRedirects() throws Exception {
346331
// Set up RedirectTransport to cause infinite redirections.
347332
RedirectTransport fakeTransport = new RedirectTransport();
@@ -359,7 +344,6 @@ public void testInfiniteRedirects() throws Exception {
359344
assertEquals(request.getNumberOfRetries() + 1, fakeTransport.lowLevelExecCalls);
360345
}
361346

362-
@Test
363347
public void testMissingLocationRedirect() throws Exception {
364348
// Set up RedirectTransport to set responses with missing location headers.
365349
RedirectTransport fakeTransport = new RedirectTransport();
@@ -469,7 +453,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) {
469453
}
470454
}
471455

472-
@Test
473456
public void testHandleRedirect() throws Exception {
474457
StatusCodesTransport transport = new StatusCodesTransport();
475458
HttpRequest req =
@@ -524,7 +507,6 @@ private void subtestRedirect(int statusCode, boolean setLocation) throws Excepti
524507
}
525508
}
526509

527-
@Test
528510
public void testHandleRedirect_relativeLocation() throws IOException {
529511
subtestHandleRedirect_relativeLocation("http://some.org/a/b", "z", "http://some.org/a/z");
530512
subtestHandleRedirect_relativeLocation("http://some.org/a/b", "z/", "http://some.org/a/z/");
@@ -544,7 +526,6 @@ public void subtestHandleRedirect_relativeLocation(
544526
}
545527

546528
@Deprecated
547-
@Test
548529
public void testExecuteErrorWithRetryEnabled() throws Exception {
549530
int callsBeforeSuccess = 3;
550531
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -559,7 +540,6 @@ public void testExecuteErrorWithRetryEnabled() throws Exception {
559540
assertEquals(4, fakeTransport.lowLevelExecCalls);
560541
}
561542

562-
@Test
563543
public void testExecuteErrorWithIOExceptionHandler() throws Exception {
564544
int callsBeforeSuccess = 3;
565545
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -575,7 +555,6 @@ public void testExecuteErrorWithIOExceptionHandler() throws Exception {
575555
}
576556

577557
@Deprecated
578-
@Test
579558
public void testExecuteErrorWithRetryEnabledBeyondRetryLimit() throws Exception {
580559
int callsBeforeSuccess = 11;
581560
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -593,7 +572,6 @@ public void testExecuteErrorWithRetryEnabledBeyondRetryLimit() throws Exception
593572
assertEquals(callsBeforeSuccess, fakeTransport.lowLevelExecCalls);
594573
}
595574

596-
@Test
597575
public void testExecuteErrorWithIOExceptionHandlerBeyondRetryLimit() throws Exception {
598576
int callsBeforeSuccess = 11;
599577
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -611,7 +589,6 @@ public void testExecuteErrorWithIOExceptionHandlerBeyondRetryLimit() throws Exce
611589
assertEquals(callsBeforeSuccess, fakeTransport.lowLevelExecCalls);
612590
}
613591

614-
@Test
615592
public void testExecuteErrorWithoutIOExceptionHandler() throws Exception {
616593
int callsBeforeSuccess = 3;
617594
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -630,7 +607,6 @@ public void testExecuteErrorWithoutIOExceptionHandler() throws Exception {
630607
}
631608

632609
@Deprecated
633-
@Test
634610
public void testUserAgentWithExecuteErrorAndRetryEnabled() throws Exception {
635611
int callsBeforeSuccess = 3;
636612
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -647,7 +623,6 @@ public void testUserAgentWithExecuteErrorAndRetryEnabled() throws Exception {
647623
assertEquals(4, fakeTransport.lowLevelExecCalls);
648624
}
649625

650-
@Test
651626
public void testUserAgentWithExecuteErrorAndIOExceptionHandler() throws Exception {
652627
int callsBeforeSuccess = 3;
653628
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -664,7 +639,6 @@ public void testUserAgentWithExecuteErrorAndIOExceptionHandler() throws Exceptio
664639
assertEquals(4, fakeTransport.lowLevelExecCalls);
665640
}
666641

667-
@Test
668642
public void testAbnormalResponseHandlerWithNoBackOff() throws Exception {
669643
FailThenSuccessBackoffTransport fakeTransport =
670644
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED, 1);
@@ -681,7 +655,6 @@ public void testAbnormalResponseHandlerWithNoBackOff() throws Exception {
681655
}
682656

683657
@Deprecated
684-
@Test
685658
public void testAbnormalResponseHandlerWithBackOff() throws Exception {
686659
FailThenSuccessBackoffTransport fakeTransport =
687660
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1);
@@ -701,7 +674,6 @@ public void testAbnormalResponseHandlerWithBackOff() throws Exception {
701674
assertTrue(handler.isCalled());
702675
}
703676

704-
@Test
705677
public void testAbnormalResponseHandlerWithBackOffUnsuccessfulResponseHandler() throws Exception {
706678
FailThenSuccessBackoffTransport fakeTransport =
707679
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1);
@@ -720,7 +692,6 @@ public void testAbnormalResponseHandlerWithBackOffUnsuccessfulResponseHandler()
720692
}
721693

722694
@Deprecated
723-
@Test
724695
public void testBackOffSingleCall() throws Exception {
725696
FailThenSuccessBackoffTransport fakeTransport =
726697
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1);
@@ -740,7 +711,6 @@ public void testBackOffSingleCall() throws Exception {
740711
assertTrue(handler.isCalled());
741712
}
742713

743-
@Test
744714
public void testBackOffUnsuccessfulResponseSingleCall() throws Exception {
745715
FailThenSuccessBackoffTransport fakeTransport =
746716
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1);
@@ -759,7 +729,6 @@ public void testBackOffUnsuccessfulResponseSingleCall() throws Exception {
759729
}
760730

761731
@Deprecated
762-
@Test
763732
public void testBackOffMultipleCalls() throws Exception {
764733
int callsBeforeSuccess = 5;
765734
FailThenSuccessBackoffTransport fakeTransport =
@@ -781,7 +750,6 @@ public void testBackOffMultipleCalls() throws Exception {
781750
assertTrue(handler.isCalled());
782751
}
783752

784-
@Test
785753
public void testBackOffUnsucessfulReponseMultipleCalls() throws Exception {
786754
int callsBeforeSuccess = 5;
787755
FailThenSuccessBackoffTransport fakeTransport =
@@ -802,7 +770,6 @@ public void testBackOffUnsucessfulReponseMultipleCalls() throws Exception {
802770
}
803771

804772
@Deprecated
805-
@Test
806773
public void testBackOffCallsBeyondRetryLimit() throws Exception {
807774
int callsBeforeSuccess = 11;
808775
FailThenSuccessBackoffTransport fakeTransport =
@@ -827,7 +794,6 @@ public void testBackOffCallsBeyondRetryLimit() throws Exception {
827794
assertTrue(handler.isCalled());
828795
}
829796

830-
@Test
831797
public void testBackOffUnsuccessfulReponseCallsBeyondRetryLimit() throws Exception {
832798
int callsBeforeSuccess = 11;
833799
FailThenSuccessBackoffTransport fakeTransport =
@@ -851,7 +817,6 @@ public void testBackOffUnsuccessfulReponseCallsBeyondRetryLimit() throws Excepti
851817
}
852818

853819
@Deprecated
854-
@Test
855820
public void testBackOffUnRecognizedStatusCode() throws Exception {
856821
FailThenSuccessBackoffTransport fakeTransport =
857822
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED, 1);
@@ -874,7 +839,6 @@ public void testBackOffUnRecognizedStatusCode() throws Exception {
874839
assertTrue(handler.isCalled());
875840
}
876841

877-
@Test
878842
public void testBackOffUnsuccessfulReponseUnRecognizedStatusCode() throws Exception {
879843
FailThenSuccessBackoffTransport fakeTransport =
880844
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED, 1);
@@ -896,7 +860,6 @@ public void testBackOffUnsuccessfulReponseUnRecognizedStatusCode() throws Except
896860
}
897861

898862
@Deprecated
899-
@Test
900863
public void testBackOffStop() throws Exception {
901864
int callsBeforeSuccess = 5;
902865
FailThenSuccessBackoffTransport fakeTransport =
@@ -923,7 +886,6 @@ public void testBackOffStop() throws Exception {
923886
assertTrue(handler.isCalled());
924887
}
925888

926-
@Test
927889
public void testBackOffUnsucessfulResponseStop() throws Exception {
928890
int callsBeforeSuccess = 5;
929891
FailThenSuccessBackoffTransport fakeTransport =
@@ -970,7 +932,6 @@ public static class MyHeaders extends HttpHeaders {
970932
@Key E otherValue;
971933
}
972934

973-
@Test
974935
public void testExecute_headerSerialization() throws Exception {
975936
// custom headers
976937
MyHeaders myHeaders = new MyHeaders();
@@ -1011,7 +972,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
1011972
assertEquals(ImmutableList.of("other"), lowLevelRequest.getHeaderValues("othervalue"));
1012973
}
1013974

1014-
@Test
1015975
public void testGZipEncoding() throws Exception {
1016976
class MyTransport extends MockHttpTransport {
1017977

@@ -1061,7 +1021,6 @@ public LowLevelHttpResponse execute() throws IOException {
10611021
request.execute();
10621022
}
10631023

1064-
@Test
10651024
public void testContentLoggingLimitWithLoggingEnabledAndDisabled() throws Exception {
10661025

10671026
class MyTransport extends MockHttpTransport {
@@ -1128,20 +1087,17 @@ public LowLevelHttpResponse execute() throws IOException {
11281087
}
11291088
}
11301089

1131-
@Test
11321090
public void testVersion() {
11331091
assertNotNull("version constant should not be null", HttpRequest.VERSION);
11341092
Pattern semverPattern = Pattern.compile("\\d+\\.\\d+\\.\\d+(-sp\\.\\d+)?(-SNAPSHOT)?");
11351093
assertTrue(semverPattern.matcher(HttpRequest.VERSION).matches());
11361094
}
11371095

1138-
@Test
11391096
public void testUserAgent() {
11401097
assertTrue(HttpRequest.USER_AGENT_SUFFIX.contains("Google-HTTP-Java-Client"));
11411098
assertTrue(HttpRequest.USER_AGENT_SUFFIX.contains("gzip"));
11421099
}
11431100

1144-
@Test
11451101
public void testExecute_headers() throws Exception {
11461102
HttpTransport transport = new MockHttpTransport();
11471103
HttpRequest request =
@@ -1151,7 +1107,6 @@ public void testExecute_headers() throws Exception {
11511107
request.execute();
11521108
}
11531109

1154-
@Test
11551110
public void testSuppressUserAgentSuffix() throws Exception {
11561111
class MyTransport extends MockHttpTransport {
11571112
String expectedUserAgent;
@@ -1194,7 +1149,6 @@ public LowLevelHttpResponse execute() throws IOException {
11941149
request.execute();
11951150
}
11961151

1197-
@Test
11981152
public void testExecuteAsync()
11991153
throws IOException, InterruptedException, ExecutionException, TimeoutException {
12001154
MockExecutor mockExecutor = new MockExecutor();
@@ -1209,7 +1163,6 @@ public void testExecuteAsync()
12091163
assertNotNull(futureResponse.get(10, TimeUnit.MILLISECONDS));
12101164
}
12111165

1212-
@Test
12131166
public void testExecute_redirects() throws Exception {
12141167
class MyTransport extends MockHttpTransport {
12151168
int count = 1;
@@ -1240,7 +1193,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
12401193
}
12411194
}
12421195

1243-
@Test
12441196
public void testExecute_redirectWithIncorrectContentRetryableSetting() throws Exception {
12451197
// TODO(yanivi): any way we can warn user about this?
12461198
RedirectTransport fakeTransport = new RedirectTransport();
@@ -1261,7 +1213,6 @@ public void testExecute_redirectWithIncorrectContentRetryableSetting() throws Ex
12611213
assertEquals(2, fakeTransport.lowLevelExecCalls);
12621214
}
12631215

1264-
@Test
12651216
public void testExecute_curlLogger() throws Exception {
12661217
LogRecordingHandler recorder = new LogRecordingHandler();
12671218
HttpTransport.LOGGER.setLevel(Level.CONFIG);
@@ -1284,7 +1235,6 @@ public void testExecute_curlLogger() throws Exception {
12841235
assertTrue(found);
12851236
}
12861237

1287-
@Test
12881238
public void testExecute_curlLoggerWithContentEncoding() throws Exception {
12891239
LogRecordingHandler recorder = new LogRecordingHandler();
12901240
HttpTransport.LOGGER.setLevel(Level.CONFIG);
@@ -1318,7 +1268,6 @@ public void testExecute_curlLoggerWithContentEncoding() throws Exception {
13181268
assertTrue(found);
13191269
}
13201270

1321-
@Test
13221271
public void testVersion_matchesAcceptablePatterns() throws Exception {
13231272
String acceptableVersionPattern =
13241273
"unknown-version|(?:\\d+\\.\\d+\\.\\d+(?:-.*?)?(?:-SNAPSHOT)?)";

0 commit comments

Comments
 (0)