Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: prepare to bump JUnit to 4.13 #7068

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions api/src/test/java/io/grpc/MethodDescriptorTest.java
Expand Up @@ -26,9 +26,7 @@
import io.grpc.MethodDescriptor.Marshaller;
import io.grpc.MethodDescriptor.MethodType;
import io.grpc.testing.TestMethodDescriptors;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

Expand All @@ -37,8 +35,6 @@
*/
@RunWith(JUnit4.class)
public class MethodDescriptorTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();

@Test
public void createMethodDescriptor() {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -50,7 +50,7 @@ subprojects {
javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"

nettyVersion = '4.1.48.Final'
guavaVersion = '28.2-android'
guavaVersion = '29.0-android'
googleauthVersion = '0.20.0'
protobufVersion = '3.12.0'
protocVersion = protobufVersion
Expand Down
2 changes: 1 addition & 1 deletion context/src/test/java/io/grpc/ContextTest.java
Expand Up @@ -17,14 +17,14 @@
package io.grpc;

import static io.grpc.Context.cancellableAncestor;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down
Expand Up @@ -20,8 +20,8 @@
import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
import static io.netty.util.AsciiString.of;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import com.google.common.collect.Iterables;
Expand Down
7 changes: 3 additions & 4 deletions repositories.bzl
Expand Up @@ -19,7 +19,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"com.google.code.gson:gson:jar:2.8.6",
"com.google.errorprone:error_prone_annotations:2.3.4",
"com.google.guava:failureaccess:1.0.1",
"com.google.guava:guava:28.2-android",
"com.google.guava:guava:29.0-android",
"com.google.j2objc:j2objc-annotations:1.3",
"com.google.truth:truth:1.0.1",
"com.squareup.okhttp:okhttp:2.7.4",
Expand Down Expand Up @@ -236,14 +236,13 @@ def com_google_errorprone_error_prone_annotations():
def com_google_guava_guava():
jvm_maven_import_external(
name = "com_google_guava_guava",
artifact = "com.google.guava:guava:28.2-android",
artifact = "com.google.guava:guava:29.0-android",
server_urls = ["https://repo.maven.apache.org/maven2/"],
artifact_sha256 = "1faf214c94723ab9fbadfedd9af88ddc325faf669e68eab04688c3afcf59c037",
artifact_sha256 = "00ba22cb0e32610db7cf8ab4c20017c85d11788600734ff1d86995345eb5bc3b",
licenses = ["notice"], # Apache 2.0
)

def com_google_guava_failureaccess():
# Not needed until Guava 27.0, but including now to ease upgrading of users. See #5214
jvm_maven_import_external(
name = "com_google_guava_failureaccess",
artifact = "com.google.guava:failureaccess:1.0.1",
Expand Down
32 changes: 20 additions & 12 deletions xds/src/test/java/io/grpc/xds/BootstrapperTest.java
Expand Up @@ -29,18 +29,15 @@
import io.grpc.xds.Bootstrapper.ServerInfo;
import java.io.IOException;
import java.util.List;
import org.junit.Rule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Unit tests for {@link Bootstrapper}. */
@RunWith(JUnit4.class)
public class BootstrapperTest {

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void parseBootstrap_validData_singleXdsServer() throws IOException {
String rawData = "{\n"
Expand Down Expand Up @@ -218,8 +215,12 @@ public void parseBootstrap_IgnoreIrrelevantFields() throws IOException {
public void parseBootstrap_emptyData() throws IOException {
String rawData = "";

thrown.expect(IOException.class);
Bootstrapper.parseConfig(rawData);
try {
Bootstrapper.parseConfig(rawData);
Assert.fail();
} catch (IOException expected) {
}

}

@Test
Expand Down Expand Up @@ -269,9 +270,12 @@ public void parseBootstrap_noXdsServers() throws IOException {
+ " }\n"
+ "}";

thrown.expect(IOException.class);
thrown.expectMessage("Invalid bootstrap: 'xds_servers' does not exist.");
Bootstrapper.parseConfig(rawData);
try {
Bootstrapper.parseConfig(rawData);
Assert.fail();
} catch (IOException ex) {
Assert.assertEquals("Invalid bootstrap: 'xds_servers' does not exist.", ex.getMessage());
}
}

@Test
Expand Down Expand Up @@ -299,9 +303,13 @@ public void parseBootstrap_serverWithoutServerUri() throws IOException {
+ " ]\n "
+ "}";

thrown.expect(IOException.class);
thrown.expectMessage("Invalid bootstrap: 'xds_servers' contains unknown server.");
Bootstrapper.parseConfig(rawData);
try {
Bootstrapper.parseConfig(rawData);
Assert.fail();
} catch (IOException ex) {
Assert.assertEquals("Invalid bootstrap: 'xds_servers' contains unknown server.",
ex.getMessage());
}
}

@SuppressWarnings("deprecation")
Expand Down
18 changes: 11 additions & 7 deletions xds/src/test/java/io/grpc/xds/WeightedRandomPickerTest.java
Expand Up @@ -28,9 +28,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
Expand All @@ -42,8 +42,6 @@
*/
@RunWith(JUnit4.class)
public class WeightedRandomPickerTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();

@Rule
public final MockitoRule mockitoRule = MockitoJUnit.rule();
Expand Down Expand Up @@ -104,14 +102,20 @@ public int nextInt(int bound) {
public void emptyList() {
List<WeightedChildPicker> emptyList = new ArrayList<>();

thrown.expect(IllegalArgumentException.class);
new WeightedRandomPicker(emptyList);
try {
new WeightedRandomPicker(emptyList);
Assert.fail();
} catch (IllegalArgumentException expected) {
}
}

@Test
public void negativeWeight() {
thrown.expect(IllegalArgumentException.class);
new WeightedChildPicker(-1, childPicker0);
try {
new WeightedChildPicker(-1, childPicker0);
Assert.fail();
} catch (IllegalArgumentException expected) {
}
}

@Test
Expand Down
25 changes: 16 additions & 9 deletions xds/src/test/java/io/grpc/xds/XdsClientImplTest.java
Expand Up @@ -111,10 +111,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -179,8 +179,6 @@ public boolean shouldAccept(Runnable command) {

@Rule
public final GrpcCleanupRule cleanupRule = new GrpcCleanupRule();
@Rule
public ExpectedException thrown = ExpectedException.none();

private final SynchronizationContext syncContext = new SynchronizationContext(
new Thread.UncaughtExceptionHandler() {
Expand Down Expand Up @@ -3441,8 +3439,11 @@ public void populateRoutesInVirtualHost_routeWithCaseInsensitiveMatch() {
.setCaseSensitive(BoolValue.newBuilder().setValue(false))))
.build();

thrown.expect(XdsClientImpl.InvalidProtoDataException.class);
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
try {
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
Assert.fail();
} catch (XdsClientImpl.InvalidProtoDataException expected) {
}
}

@Test
Expand All @@ -3460,8 +3461,11 @@ public void populateRoutesInVirtualHost_lastRouteIsNotDefaultRoute() {
.setCaseSensitive(BoolValue.newBuilder().setValue(true))))
.build();

thrown.expect(XdsClientImpl.InvalidProtoDataException.class);
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
try {
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
Assert.fail();
} catch (XdsClientImpl.InvalidProtoDataException expected) {
}
}

@Test
Expand All @@ -3485,8 +3489,11 @@ public void populateRoutesInVirtualHost_NoUsableRoute() {
.addQueryParameters(QueryParameterMatcher.getDefaultInstance())))
.build();

thrown.expect(XdsClientImpl.InvalidProtoDataException.class);
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
try {
XdsClientImpl.populateRoutesInVirtualHost(virtualHost);
Assert.fail();
} catch (XdsClientImpl.InvalidProtoDataException expected) {
}
}

@Test
Expand Down
21 changes: 12 additions & 9 deletions xds/src/test/java/io/grpc/xds/XdsClientTest.java
Expand Up @@ -23,9 +23,8 @@

import io.grpc.xds.XdsClient.RefCountedXdsClientObjectPool;
import io.grpc.xds.XdsClient.XdsClientFactory;
import org.junit.Rule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

Expand All @@ -34,8 +33,6 @@
*/
@RunWith(JUnit4.class)
public class XdsClientTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();

@Test
public void refCountedXdsClientObjectPool_getObjectShouldMatchReturnObject() {
Expand All @@ -61,9 +58,12 @@ XdsClient createXdsClient() {
verify(xdsClient).shutdown();
assertThat(xdsClientPool.xdsClient).isNull();

thrown.expect(IllegalStateException.class);
// returnOject for the 3rd time
xdsClientPool.returnObject(xdsClient);
// returnObject for the 3rd time
try {
xdsClientPool.returnObject(xdsClient);
Assert.fail();
} catch (IllegalStateException expected) {
}
}

@Test
Expand All @@ -79,8 +79,11 @@ XdsClient createXdsClient() {

xdsClientPool.getObject();

thrown.expect(IllegalStateException.class);
xdsClientPool.returnObject(mock(XdsClient.class));
try {
xdsClientPool.returnObject(mock(XdsClient.class));
Assert.fail();
} catch (IllegalStateException expected) {
}
}

@Test
Expand Down