diff options
| author | Kristen Kozak <sebright@google.com> | 2018-04-03 16:37:22 -0700 |
|---|---|---|
| committer | Kristen Kozak <sebright@google.com> | 2018-04-04 19:42:51 -0700 |
| commit | 952d64323cf95aa2fe04ddb6188303bac8a5fb35 (patch) | |
| tree | e667a5d7ee7a488843379939c844f5463254b8b7 /api | |
| parent | 37730f70bdd2ee7ff214cc4ed7fb3d451a6dada7 (diff) | |
| download | platform_external_opencensus-java-952d64323cf95aa2fe04ddb6188303bac8a5fb35.tar.gz platform_external_opencensus-java-952d64323cf95aa2fe04ddb6188303bac8a5fb35.tar.bz2 platform_external_opencensus-java-952d64323cf95aa2fe04ddb6188303bac8a5fb35.zip | |
Replace Guava VisibleForTesting in opencensus-api (issue #1081).
This commit adds two annotations to replace the uses of Guava's
VisibleForTesting annotation in opencensus-api. Each annotation has a more
specific meaning than VisibleForTesting, to make the uses of the annotations
more informative.
DefaultVisibilityForTesting - This annotation replaces the main use of
@VisibleForTesting, indicating that an element was changed from private to
package-private for testing.
PublicForTesting - This annotation is temporary and should be removed as part
of issue #977.
Diffstat (limited to 'api')
10 files changed, 91 insertions, 16 deletions
diff --git a/api/src/main/java/io/opencensus/internal/DefaultVisibilityForTesting.java b/api/src/main/java/io/opencensus/internal/DefaultVisibilityForTesting.java new file mode 100644 index 00000000..e90a6573 --- /dev/null +++ b/api/src/main/java/io/opencensus/internal/DefaultVisibilityForTesting.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018, OpenCensus Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opencensus.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that an element is package-private instead of private only for the purpose of testing. + * This annotation is only meant to be used as documentation in the source code. + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE +}) +public @interface DefaultVisibilityForTesting {} diff --git a/api/src/main/java/io/opencensus/internal/PublicForTesting.java b/api/src/main/java/io/opencensus/internal/PublicForTesting.java new file mode 100644 index 00000000..cfd37ff2 --- /dev/null +++ b/api/src/main/java/io/opencensus/internal/PublicForTesting.java @@ -0,0 +1,38 @@ +/* + * Copyright 2018, OpenCensus Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opencensus.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that an element is public instead of package-private only for the purpose of testing. + * This annotation is only meant to be used as documentation in the source code. + */ +// TODO(#977): All uses of this annotation should be removed or replaced with @Internal. +@Retention(RetentionPolicy.SOURCE) +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE +}) +public @interface PublicForTesting {} diff --git a/api/src/main/java/io/opencensus/stats/Measure.java b/api/src/main/java/io/opencensus/stats/Measure.java index ddd25763..4b47cd79 100644 --- a/api/src/main/java/io/opencensus/stats/Measure.java +++ b/api/src/main/java/io/opencensus/stats/Measure.java @@ -17,8 +17,8 @@ package io.opencensus.stats; import com.google.auto.value.AutoValue; -import com.google.common.annotations.VisibleForTesting; import io.opencensus.common.Function; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.StringUtils; import io.opencensus.internal.Utils; import javax.annotation.concurrent.Immutable; @@ -31,7 +31,7 @@ import javax.annotation.concurrent.Immutable; @Immutable public abstract class Measure { - @VisibleForTesting static final int NAME_MAX_LENGTH = 255; + @DefaultVisibilityForTesting static final int NAME_MAX_LENGTH = 255; /** * Applies the given match function to the underlying data type. diff --git a/api/src/main/java/io/opencensus/stats/Stats.java b/api/src/main/java/io/opencensus/stats/Stats.java index d7f77e34..8393f631 100644 --- a/api/src/main/java/io/opencensus/stats/Stats.java +++ b/api/src/main/java/io/opencensus/stats/Stats.java @@ -16,7 +16,7 @@ package io.opencensus.stats; -import com.google.common.annotations.VisibleForTesting; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.Provider; import java.util.logging.Level; import java.util.logging.Logger; @@ -89,7 +89,7 @@ public final class Stats { } // Any provider that may be used for StatsComponent can be added here. - @VisibleForTesting + @DefaultVisibilityForTesting static StatsComponent loadStatsComponent(@Nullable ClassLoader classLoader) { try { // Call Class.forName with literal string name of the class to help shading tools. diff --git a/api/src/main/java/io/opencensus/stats/View.java b/api/src/main/java/io/opencensus/stats/View.java index 42179d58..f563ff9a 100644 --- a/api/src/main/java/io/opencensus/stats/View.java +++ b/api/src/main/java/io/opencensus/stats/View.java @@ -17,9 +17,9 @@ package io.opencensus.stats; import com.google.auto.value.AutoValue; -import com.google.common.annotations.VisibleForTesting; import io.opencensus.common.Duration; import io.opencensus.common.Function; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.StringUtils; import io.opencensus.internal.Utils; import io.opencensus.tags.TagKey; @@ -42,7 +42,7 @@ import javax.annotation.concurrent.Immutable; @SuppressWarnings("deprecation") public abstract class View { - @VisibleForTesting static final int NAME_MAX_LENGTH = 255; + @DefaultVisibilityForTesting static final int NAME_MAX_LENGTH = 255; private static final Comparator<TagKey> TAG_KEY_COMPARATOR = new Comparator<TagKey>() { diff --git a/api/src/main/java/io/opencensus/tags/Tags.java b/api/src/main/java/io/opencensus/tags/Tags.java index e4c6a579..07123647 100644 --- a/api/src/main/java/io/opencensus/tags/Tags.java +++ b/api/src/main/java/io/opencensus/tags/Tags.java @@ -16,7 +16,7 @@ package io.opencensus.tags; -import com.google.common.annotations.VisibleForTesting; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.Provider; import io.opencensus.tags.propagation.TagPropagationComponent; import java.util.logging.Level; @@ -91,7 +91,7 @@ public final class Tags { } // Any provider that may be used for TagsComponent can be added here. - @VisibleForTesting + @DefaultVisibilityForTesting static TagsComponent loadTagsComponent(@Nullable ClassLoader classLoader) { try { // Call Class.forName with literal string name of the class to help shading tools. diff --git a/api/src/main/java/io/opencensus/trace/Status.java b/api/src/main/java/io/opencensus/trace/Status.java index 0a0e45ce..5296541c 100644 --- a/api/src/main/java/io/opencensus/trace/Status.java +++ b/api/src/main/java/io/opencensus/trace/Status.java @@ -16,9 +16,9 @@ package io.opencensus.trace; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import io.opencensus.internal.PublicForTesting; import io.opencensus.internal.Utils; import java.util.ArrayList; import java.util.Collections; @@ -229,7 +229,7 @@ public final class Status { * @return the status that has the current {@code CanonicalCode}. * @since 0.5 */ - @VisibleForTesting + @PublicForTesting public Status toStatus() { return STATUS_LIST.get(value); } diff --git a/api/src/main/java/io/opencensus/trace/TraceOptions.java b/api/src/main/java/io/opencensus/trace/TraceOptions.java index ee09376f..c5d44f45 100644 --- a/api/src/main/java/io/opencensus/trace/TraceOptions.java +++ b/api/src/main/java/io/opencensus/trace/TraceOptions.java @@ -16,9 +16,9 @@ package io.opencensus.trace; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.Utils; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -241,7 +241,7 @@ public final class TraceOptions { } // Returns the current set of options bitmask. - @VisibleForTesting + @DefaultVisibilityForTesting byte getOptions() { return options; } diff --git a/api/src/main/java/io/opencensus/trace/Tracing.java b/api/src/main/java/io/opencensus/trace/Tracing.java index e67eb008..f55cd775 100644 --- a/api/src/main/java/io/opencensus/trace/Tracing.java +++ b/api/src/main/java/io/opencensus/trace/Tracing.java @@ -16,8 +16,8 @@ package io.opencensus.trace; -import com.google.common.annotations.VisibleForTesting; import io.opencensus.common.Clock; +import io.opencensus.internal.DefaultVisibilityForTesting; import io.opencensus.internal.Provider; import io.opencensus.trace.config.TraceConfig; import io.opencensus.trace.export.ExportComponent; @@ -87,7 +87,7 @@ public final class Tracing { } // Any provider that may be used for TraceComponent can be added here. - @VisibleForTesting + @DefaultVisibilityForTesting static TraceComponent loadTraceComponent(@Nullable ClassLoader classLoader) { try { // Call Class.forName with literal string name of the class to help shading tools. diff --git a/api/src/main/java/io/opencensus/trace/export/SampledSpanStore.java b/api/src/main/java/io/opencensus/trace/export/SampledSpanStore.java index 3ee80ce2..99bc5288 100644 --- a/api/src/main/java/io/opencensus/trace/export/SampledSpanStore.java +++ b/api/src/main/java/io/opencensus/trace/export/SampledSpanStore.java @@ -17,7 +17,7 @@ package io.opencensus.trace.export; import com.google.auto.value.AutoValue; -import com.google.common.annotations.VisibleForTesting; +import io.opencensus.internal.PublicForTesting; import io.opencensus.internal.Utils; import io.opencensus.trace.Span; import io.opencensus.trace.Status; @@ -129,7 +129,7 @@ public abstract class SampledSpanStore { * @return the set of unique span names registered to the library. * @since 0.7 */ - @VisibleForTesting + @PublicForTesting public abstract Set<String> getRegisteredSpanNamesForCollection(); /** |
