Skip to content

Commit 4c1bab9

Browse files
committed
Prepare for JUnit 4.13
It deprecates ExpectedException and Assert.assertThat(T, org.hamcrest.Matcher). Without Java 8 we don't want to migrate away from ExpectedException at this time. We tend to prefer Truth over Hamcrest, so I swapped the one instance of Assert.assertThat() to use Truth. With this change we get a warning-less build with JUnit 4.13. We don't yet upgrade because we still need to support JUnit 4.12 for some use-cases, but will be able to upgrade to 4.13 soon when they upgrade.
1 parent 2adeff5 commit 4c1bab9

34 files changed

+37
-5
lines changed

api/src/test/java/io/grpc/ContextsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
package io.grpc;
1818

19+
import static com.google.common.truth.Truth.assertThat;
1920
import static io.grpc.Contexts.interceptCall;
2021
import static io.grpc.Contexts.statusFromCancelled;
21-
import static org.hamcrest.core.IsInstanceOf.instanceOf;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertFalse;
2424
import static org.junit.Assert.assertNotNull;
2525
import static org.junit.Assert.assertNull;
2626
import static org.junit.Assert.assertSame;
27-
import static org.junit.Assert.assertThat;
2827
import static org.junit.Assert.assertTrue;
2928
import static org.junit.Assert.fail;
3029

@@ -240,7 +239,7 @@ class MockScheduledExecutorService extends ForwardingScheduledExecutorService {
240239
executorService.command.run();
241240

242241
assertTrue(cancellableContext.isCancelled());
243-
assertThat(cancellableContext.cancellationCause(), instanceOf(TimeoutException.class));
242+
assertThat(cancellableContext.cancellationCause()).isInstanceOf(TimeoutException.class);
244243

245244
Status status = statusFromCancelled(cancellableContext);
246245
assertNotNull(status);

api/src/test/java/io/grpc/MetadataTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
@RunWith(JUnit4.class)
5050
public class MetadataTest {
5151

52+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5253
@Rule public final ExpectedException thrown = ExpectedException.none();
5354

5455
private static final Metadata.BinaryMarshaller<Fish> FISH_MARSHALLER =

api/src/test/java/io/grpc/MethodDescriptorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
@RunWith(JUnit4.class)
3939
public class MethodDescriptorTest {
40+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4041
@Rule
4142
public final ExpectedException thrown = ExpectedException.none();
4243

api/src/test/java/io/grpc/ServerInterceptorsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ServerInterceptorsTest {
5656
@Rule
5757
public final MockitoRule mocks = MockitoJUnit.rule();
5858

59+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5960
@Rule
6061
public final ExpectedException thrown = ExpectedException.none();
6162

api/src/test/java/io/grpc/ServerServiceDefinitionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ServerServiceDefinitionTest {
5252
= ServerMethodDefinition.create(method1, methodHandler1);
5353
private ServerMethodDefinition<String, Integer> methodDef2
5454
= ServerMethodDefinition.create(method2, methodHandler2);
55+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
5556
@Rule
5657
public ExpectedException thrown = ExpectedException.none();
5758

api/src/test/java/io/grpc/ServiceDescriptorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@RunWith(JUnit4.class)
3737
public class ServiceDescriptorTest {
3838

39+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
3940
@Rule
4041
public final ExpectedException thrown = ExpectedException.none();
4142

core/src/test/java/io/grpc/internal/AbstractClientStreamTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
public class AbstractClientStreamTest {
7676

7777
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
78+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
7879
@Rule public final ExpectedException thrown = ExpectedException.none();
7980

8081
private final StatsTraceContext statsTraceCtx = StatsTraceContext.NOOP;

core/src/test/java/io/grpc/internal/AbstractServerStreamTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class AbstractServerStreamTest {
5757
private static final int TIMEOUT_MS = 1000;
5858
private static final int MAX_MESSAGE_SIZE = 100;
5959

60+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
6061
@Rule public final ExpectedException thrown = ExpectedException.none();
6162

6263
private final WritableBufferAllocator allocator = new WritableBufferAllocator() {

core/src/test/java/io/grpc/internal/AbstractTransportTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata
224224
}
225225
}));
226226

227+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
227228
@Rule
228229
public ExpectedException thrown = ExpectedException.none();
229230

core/src/test/java/io/grpc/internal/ConnectivityStateManagerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
@RunWith(JUnit4.class)
4040
public class ConnectivityStateManagerTest {
41+
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
4142
@Rule
4243
public final ExpectedException thrown = ExpectedException.none();
4344

0 commit comments

Comments
 (0)