Skip to content

Commit

Permalink
use java 8 for tests (#1237)
Browse files Browse the repository at this point in the history
* use java 8 for tests, and disabled specific errorprone checks for tests

* modified existing test to use java 8 features

* updated contributing doc
  • Loading branch information
jarebudev authored Jun 17, 2020
1 parent fccc6d9 commit 22f5b1a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ $ git commit -m "Update javadoc for API."
possible, for any new value classes. Remember to add package-private
constructors to all AutoValue classes to prevent classes in other packages
from extending them.


### Unit Tests

* Unit tests target Java 8, so language features such as lambda and streams can be used in tests.


## Building opentelemetry-java

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -58,21 +57,8 @@ public class HttpTraceContextTest {
"00-" + TRACE_ID_BASE16 + "-" + SPAN_ID_BASE16 + "-01";
private static final String TRACEPARENT_HEADER_NOT_SAMPLED =
"00-" + TRACE_ID_BASE16 + "-" + SPAN_ID_BASE16 + "-00";
private static final Setter<Map<String, String>> setter =
new Setter<Map<String, String>>() {
@Override
public void set(Map<String, String> carrier, String key, String value) {
carrier.put(key, value);
}
};
private static final Getter<Map<String, String>> getter =
new Getter<Map<String, String>>() {
@Nullable
@Override
public String get(Map<String, String> carrier, String key) {
return carrier.get(key);
}
};
private static final Setter<Map<String, String>> setter = Map::put;
private static final Getter<Map<String, String>> getter = (carrier, key) -> carrier.get(key);
// Encoding preserves the order which is the reverse order of adding.
private static final String TRACESTATE_NOT_DEFAULT_ENCODING = "bar=baz,foo=bar";
private static final String TRACESTATE_NOT_DEFAULT_ENCODING_WITH_SPACES =
Expand Down Expand Up @@ -105,12 +91,7 @@ public void inject_NullCarrierUsage() {
httpTraceContext.inject(
context,
null,
new Setter<Map<String, String>>() {
@Override
public void set(Map<String, String> ignored, String key, String value) {
carrier.put(key, value);
}
});
(Setter<Map<String, String>>) (ignored, key, value) -> carrier.put(key, value));
assertThat(carrier).containsExactly(TRACE_PARENT, TRACEPARENT_HEADER_SAMPLED);
}

Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ configure(opentelemetryProjects) {
compileTestJava {
// serialVersionUID is basically guaranteed to be useless in tests
options.compilerArgs += ["-Xlint:-serial"]
sourceCompatibility = 1.8
targetCompatibility = 1.8

// Disable Java7 checks in test sources
options.errorprone.disable("Java7ApiChecker")
// Disable AndroidJdkLibs checks in test sources
options.errorprone.disable("AndroidJdkLibsChecker")
}

jar.manifest {
Expand Down

0 comments on commit 22f5b1a

Please sign in to comment.