diff options
| author | Kristen Kozak <sebright@google.com> | 2017-11-08 14:45:46 -0800 |
|---|---|---|
| committer | Kristen Kozak <sebright@google.com> | 2017-11-10 11:23:50 -0800 |
| commit | 6cbf3adbc630774b341cd7958ceed8140696e71f (patch) | |
| tree | cbb650426adf2d264e0c152da16e09c4f76a019e | |
| parent | 80b8b631b47e6db4cd3f543adeb4059b14d3033a (diff) | |
| download | platform_external_opencensus-java-6cbf3adbc630774b341cd7958ceed8140696e71f.tar.gz platform_external_opencensus-java-6cbf3adbc630774b341cd7958ceed8140696e71f.tar.bz2 platform_external_opencensus-java-6cbf3adbc630774b341cd7958ceed8140696e71f.zip | |
Combine tests for Tags.getState and Tags.setState.
These tests modify global state, so combining them into a single test prevents
any order-dependent behavior.
| -rw-r--r-- | api/src/test/java/io/opencensus/tags/TagsTest.java | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/api/src/test/java/io/opencensus/tags/TagsTest.java b/api/src/test/java/io/opencensus/tags/TagsTest.java index 5cab5b45..dee517b6 100644 --- a/api/src/test/java/io/opencensus/tags/TagsTest.java +++ b/api/src/test/java/io/opencensus/tags/TagsTest.java @@ -56,22 +56,20 @@ public class TagsTest { .isEqualTo("io.opencensus.tags.NoopTags$NoopTagsComponent"); } - @Test - public void getState() { - assertThat(Tags.getState()).isEqualTo(TaggingState.DISABLED); - } - + // There is only one test that modifies tagging state in the Tags class, since the state is + // global, and it could affect other tests. NoopTagsTest has more thorough tests for tagging + // state. @Test @SuppressWarnings("deprecation") - public void setState_IgnoresInput() { + public void testState() { + // Test that setState ignores its input. Tags.setState(TaggingState.ENABLED); assertThat(Tags.getState()).isEqualTo(TaggingState.DISABLED); - } - @Test(expected = NullPointerException.class) - @SuppressWarnings("deprecation") - public void setState_DisallowsNull() { - Tags.setState(null); + // Test that setState cannot be called after getState. + thrown.expect(IllegalStateException.class); + thrown.expectMessage("State was already read, cannot set state."); + Tags.setState(TaggingState.ENABLED); } @Test |
