Remove the exclusion of TestExceptionRefactoring from errorprone config. (#919)

Signed-off-by: Bogdan Cristian Drutu <bogdandrutu@gmail.com>
This commit is contained in:
Bogdan Drutu 2020-02-24 11:36:35 -08:00 committed by GitHub
parent 30e3bc8c63
commit 8c9f928340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 23 deletions

View File

@ -48,7 +48,7 @@ public class BinaryTraceContextTest {
101, 102, 103, 104, 2, 1
};
private static final SpanContext INVALID_SPAN_CONTEXT = DefaultSpan.getInvalid().getContext();
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public ExpectedException thrown = ExpectedException.none();
private final BinaryFormat<SpanContext> binaryFormat = new BinaryTraceContext();
private void testSpanContextConversion(SpanContext spanContext) {
@ -76,8 +76,10 @@ public class BinaryTraceContextTest {
SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()));
}
@Test(expected = NullPointerException.class)
@Test
public void toBinaryValue_NullSpanContext() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("spanContext");
binaryFormat.toByteArray(null);
}
@ -98,22 +100,24 @@ public class BinaryTraceContextTest {
TRACE_ID, SPAN_ID, TRACE_OPTIONS, TraceState.getDefault()));
}
@Test(expected = NullPointerException.class)
@Test
public void fromBinaryValue_NullInput() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("bytes");
binaryFormat.fromByteArray(null);
}
@Test
public void fromBinaryValue_EmptyInput() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Unsupported version.");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unsupported version.");
binaryFormat.fromByteArray(new byte[0]);
}
@Test
public void fromBinaryValue_UnsupportedVersionId() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Unsupported version.");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unsupported version.");
binaryFormat.fromByteArray(
new byte[] {
66, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 97, 98, 99, 100, 101,
@ -123,8 +127,8 @@ public class BinaryTraceContextTest {
@Test
public void fromBinaryValue_UnsupportedFieldIdFirst() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Invalid input: expected trace ID at offset "
+ BinaryTraceContext.TRACE_ID_FIELD_ID_OFFSET);
binaryFormat.fromByteArray(
@ -136,8 +140,8 @@ public class BinaryTraceContextTest {
@Test
public void fromBinaryValue_UnsupportedFieldIdSecond() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Invalid input: expected span ID at offset " + BinaryTraceContext.SPAN_ID_FIELD_ID_OFFSET);
binaryFormat.fromByteArray(
new byte[] {
@ -161,23 +165,23 @@ public class BinaryTraceContextTest {
@Test
public void fromBinaryValue_ShorterTraceId() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Invalid input: truncated");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid input: truncated");
binaryFormat.fromByteArray(
new byte[] {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76});
}
@Test
public void fromBinaryValue_ShorterSpanId() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Invalid input: truncated");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid input: truncated");
binaryFormat.fromByteArray(new byte[] {0, 1, 97, 98, 99, 100, 101, 102, 103});
}
@Test
public void fromBinaryValue_ShorterTraceFlags() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Invalid input: truncated");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid input: truncated");
binaryFormat.fromByteArray(
new byte[] {
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100,

View File

@ -53,7 +53,6 @@ subprojects {
// ExpectedExceptionRefactoring and TestExceptionRefactoring suggest using
// assertThrows, but assertThrows only works well with lambdas.
it.options.errorprone.disable("ExpectedExceptionRefactoring") // "-Xep:ExpectedExceptionRefactoring:OFF"
it.options.errorprone.disable("TestExceptionRefactoring") // "-Xep:TestExceptionRefactoring:OFF"
// AutoValueImmutableFields suggests returning Guava types from API methods
it.options.errorprone.disable("AutoValueImmutableFields") // "-Xep:AutoValueImmutableFields:OFF"

View File

@ -50,9 +50,10 @@ public final class TraceShim {
*/
public static io.opentracing.Tracer createTracerShim(
TracerProvider tracerProvider, CorrelationContextManager contextManager) {
Utils.checkNotNull(tracerProvider, "tracerProvider");
Utils.checkNotNull(contextManager, "contextManager");
return new TracerShim(new TelemetryInfo(getTracer(tracerProvider), contextManager));
return new TracerShim(
new TelemetryInfo(
getTracer(Utils.checkNotNull(tracerProvider, "tracerProvider")),
Utils.checkNotNull(contextManager, "contextManager")));
}
private static Tracer getTracer(TracerProvider tracerProvider) {

View File

@ -21,9 +21,12 @@ import static org.junit.Assert.assertEquals;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.sdk.correlationcontext.CorrelationContextManagerSdk;
import io.opentelemetry.sdk.trace.TracerSdkProvider;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class TraceShimTest {
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test
public void createTracerShim_default() {
@ -32,13 +35,17 @@ public class TraceShimTest {
assertEquals(OpenTelemetry.getCorrelationContextManager(), tracerShim.contextManager());
}
@Test(expected = NullPointerException.class)
@Test
public void createTracerShim_nullTracer() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("tracerProvider");
TraceShim.createTracerShim(null, OpenTelemetry.getCorrelationContextManager());
}
@Test(expected = NullPointerException.class)
@Test
public void createTracerShim_nullContextManager() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("contextManager");
TraceShim.createTracerShim(OpenTelemetry.getTracerRegistry(), null);
}