Skip to content

Commit 7599092

Browse files
committed
chore: use JUnit4 in tests
this is basically not rely on extending TestCase and using @test annotations
1 parent e648262 commit 7599092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+787
-227
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
19+
1720
import java.io.IOException;
1821
import java.io.OutputStream;
1922
import java.util.Arrays;
2023
import junit.framework.TestCase;
24+
import org.junit.Test;
2125

2226
/**
2327
* Tests {@link AbstractHttpContent}.
2428
*
2529
* @author Yaniv Inbar
2630
*/
27-
public class AbstractHttpContentTest extends TestCase {
31+
public class AbstractHttpContentTest {
2832

2933
static class TestHttpContent extends AbstractHttpContent {
3034

@@ -54,11 +58,13 @@ public boolean retrySupported() {
5458
}
5559
}
5660

61+
@Test
5762
public void testRetrySupported() {
5863
AbstractHttpContent content = new TestHttpContent(true, 0);
5964
assertTrue(content.retrySupported());
6065
}
6166

67+
@Test
6268
public void testComputeLength() throws Exception {
6369
subtestComputeLength(true, 0, 0);
6470
subtestComputeLength(true, 1, 1);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,34 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
1719
import com.google.api.client.testing.http.HttpTesting;
1820
import com.google.api.client.testing.http.MockHttpTransport;
1921
import junit.framework.TestCase;
22+
import org.junit.Test;
2023

2124
/**
2225
* Tests {@link BasicAuthentication}.
2326
*
2427
* @author Yaniv Inbar
2528
*/
26-
public class BasicAuthenticationTest extends TestCase {
29+
public class BasicAuthenticationTest {
2730

2831
static final String USERNAME = "Aladdin";
2932

3033
static final String PASSWORD = "open sesame";
3134

3235
static final String AUTH_HEADER = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
3336

37+
@Test
3438
public void testConstructor() {
3539
BasicAuthentication auth = new BasicAuthentication(USERNAME, PASSWORD);
3640
assertEquals(USERNAME, auth.getUsername());
3741
assertEquals(PASSWORD, auth.getPassword());
3842
}
3943

44+
@Test
4045
public void testInitialize() throws Exception {
4146
BasicAuthentication auth = new BasicAuthentication(USERNAME, PASSWORD);
4247
HttpRequest request =

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
19+
import static org.junit.Assert.fail;
20+
1721
import com.google.api.client.util.IOUtils;
1822
import com.google.api.client.util.StringUtils;
1923
import java.io.ByteArrayOutputStream;
2024
import java.io.IOException;
2125
import junit.framework.TestCase;
26+
import org.junit.Test;
2227

2328
/**
2429
* Tests {@link ByteArrayContent}.
2530
*
2631
* @author Yaniv Inbar
2732
*/
28-
public class ByteArrayContentTest extends TestCase {
33+
public class ByteArrayContentTest {
2934
private static final byte[] FOO = StringUtils.getBytesUtf8("foo");
3035

36+
@Test
3137
public void testConstructor() throws IOException {
3238
subtestConstructor(new ByteArrayContent("type", FOO), "foo");
3339
subtestConstructor(new ByteArrayContent("type", FOO, 0, 3), "foo");

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertNull;
19+
import static org.junit.Assert.assertTrue;
20+
1721
import java.io.ByteArrayOutputStream;
1822
import java.io.IOException;
1923
import junit.framework.TestCase;
24+
import org.junit.Test;
2025

2126
/**
2227
* Tests {@link EmptyContent}.
2328
*
2429
* @author Yaniv Inbar
2530
*/
26-
public class EmptyContentTest extends TestCase {
31+
public class EmptyContentTest {
2732

33+
@Test
2834
public void test() throws IOException {
2935
EmptyContent content = new EmptyContent();
3036
assertEquals(0L, content.getLength());

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414

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

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
19+
1720
import com.google.api.client.util.NanoClock;
1821
import junit.framework.TestCase;
22+
import org.junit.Test;
1923

2024
/**
2125
* Tests {@link ExponentialBackOffPolicy}.
2226
*
2327
* @author Ravi Mistry
2428
*/
2529
@Deprecated
26-
public class ExponentialBackOffPolicyTest extends TestCase {
27-
28-
public ExponentialBackOffPolicyTest(String name) {
29-
super(name);
30-
}
30+
public class ExponentialBackOffPolicyTest {
3131

32+
@Test
3233
public void testConstructor() {
3334
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
3435
assertEquals(
@@ -39,15 +40,16 @@ public void testConstructor() {
3940
backOffPolicy.getCurrentIntervalMillis());
4041
assertEquals(
4142
ExponentialBackOffPolicy.DEFAULT_RANDOMIZATION_FACTOR,
42-
backOffPolicy.getRandomizationFactor());
43-
assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier());
43+
backOffPolicy.getRandomizationFactor(), 0);
44+
assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier(), 0);
4445
assertEquals(
4546
ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL_MILLIS, backOffPolicy.getMaxIntervalMillis());
4647
assertEquals(
4748
ExponentialBackOffPolicy.DEFAULT_MAX_ELAPSED_TIME_MILLIS,
4849
backOffPolicy.getMaxElapsedTimeMillis());
4950
}
5051

52+
@Test
5153
public void testBuilder() {
5254
ExponentialBackOffPolicy backOffPolicy = ExponentialBackOffPolicy.builder().build();
5355
assertEquals(
@@ -58,8 +60,8 @@ public void testBuilder() {
5860
backOffPolicy.getCurrentIntervalMillis());
5961
assertEquals(
6062
ExponentialBackOffPolicy.DEFAULT_RANDOMIZATION_FACTOR,
61-
backOffPolicy.getRandomizationFactor());
62-
assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier());
63+
backOffPolicy.getRandomizationFactor(), 0);
64+
assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier(), 0);
6365
assertEquals(
6466
ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL_MILLIS, backOffPolicy.getMaxIntervalMillis());
6567
assertEquals(
@@ -82,12 +84,13 @@ public void testBuilder() {
8284
.build();
8385
assertEquals(testInitialInterval, backOffPolicy.getInitialIntervalMillis());
8486
assertEquals(testInitialInterval, backOffPolicy.getCurrentIntervalMillis());
85-
assertEquals(testRandomizationFactor, backOffPolicy.getRandomizationFactor());
86-
assertEquals(testMultiplier, backOffPolicy.getMultiplier());
87+
assertEquals(testRandomizationFactor, backOffPolicy.getRandomizationFactor(), 0);
88+
assertEquals(testMultiplier, backOffPolicy.getMultiplier(), 0);
8789
assertEquals(testMaxInterval, backOffPolicy.getMaxIntervalMillis());
8890
assertEquals(testMaxElapsedTime, backOffPolicy.getMaxElapsedTimeMillis());
8991
}
9092

93+
@Test
9194
public void testBackOff() throws Exception {
9295
int testInitialInterval = 500;
9396
double testRandomizationFactor = 0.1;
@@ -130,13 +133,15 @@ public long nanoTime() {
130133
}
131134
}
132135

136+
@Test
133137
public void testGetElapsedTimeMillis() {
134138
ExponentialBackOffPolicy backOffPolicy =
135139
new ExponentialBackOffPolicy.Builder().setNanoClock(new MyNanoClock()).build();
136140
long elapsedTimeMillis = backOffPolicy.getElapsedTimeMillis();
137141
assertEquals("elapsedTimeMillis=" + elapsedTimeMillis, 1000, elapsedTimeMillis);
138142
}
139143

144+
@Test
140145
public void testBackOffOverflow() throws Exception {
141146
int testInitialInterval = Integer.MAX_VALUE / 2;
142147
double testMultiplier = 2.1;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@
1414

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

17+
import static org.junit.Assert.assertFalse;
18+
1719
import com.google.api.client.testing.util.TestableByteArrayOutputStream;
1820
import com.google.api.client.util.ByteArrayStreamingContent;
1921
import com.google.api.client.util.StringUtils;
2022
import java.io.IOException;
2123
import junit.framework.TestCase;
2224
import org.junit.Assert;
25+
import org.junit.Test;
2326

2427
/**
2528
* Tests {@link GZipEncoding}.
2629
*
2730
* @author Yaniv Inbar
2831
*/
29-
public class GZipEncodingTest extends TestCase {
32+
public class GZipEncodingTest {
3033

3134
private static final byte[] EXPECED_ZIPPED =
3235
new byte[] {
@@ -42,6 +45,7 @@ public class GZipEncodingTest extends TestCase {
4245
0, 0, 0, 0, 0, 0, 0, 0
4346
};
4447

48+
@Test
4549
public void test() throws IOException {
4650
// TODO: remove when no longer using Java < 16.
4751
byte[] expected =

0 commit comments

Comments
 (0)