aboutsummaryrefslogtreecommitdiff
path: root/api/src/test/java
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2018-04-17 19:57:22 -0700
committerKristen Kozak <sebright@google.com>2018-04-17 19:57:22 -0700
commit7dca0fedefb1187d34a8ca1ebbe5c5558f42aac4 (patch)
tree01371126a732bca829ece3f7cef1ef2ce0d47298 /api/src/test/java
parent7ca65408da7ac6d9f3f4ce55ee2471091365ff97 (diff)
downloadopencensus-java-7dca0fedefb1187d34a8ca1ebbe5c5558f42aac4.tar.gz
Move utils used by Duration and Timestamp from i.o.internal.Utils to TimeUtils.
This change breaks the circular dependency between io.opencensus.internal and io.opencensus.common.
Diffstat (limited to 'api/src/test/java')
-rw-r--r--api/src/test/java/io/opencensus/common/TimeUtilsTest.java60
-rw-r--r--api/src/test/java/io/opencensus/internal/UtilsTest.java29
2 files changed, 60 insertions, 29 deletions
diff --git a/api/src/test/java/io/opencensus/common/TimeUtilsTest.java b/api/src/test/java/io/opencensus/common/TimeUtilsTest.java
new file mode 100644
index 00000000..d6228566
--- /dev/null
+++ b/api/src/test/java/io/opencensus/common/TimeUtilsTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.common;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link TimeUtils}. */
+@RunWith(JUnit4.class)
+public final class TimeUtilsTest {
+
+ @Rule public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void compareLongs() {
+ assertThat(TimeUtils.compareLongs(-1L, 1L)).isLessThan(0);
+ assertThat(TimeUtils.compareLongs(10L, 10L)).isEqualTo(0);
+ assertThat(TimeUtils.compareLongs(1L, 0L)).isGreaterThan(0);
+ }
+
+ @Test
+ public void checkedAdd_TooLow() {
+ thrown.expect(ArithmeticException.class);
+ thrown.expectMessage("Long sum overflow: x=-9223372036854775807, y=-2");
+ TimeUtils.checkedAdd(Long.MIN_VALUE + 1, -2);
+ }
+
+ @Test
+ public void checkedAdd_TooHigh() {
+ thrown.expect(ArithmeticException.class);
+ thrown.expectMessage("Long sum overflow: x=9223372036854775806, y=2");
+ TimeUtils.checkedAdd(Long.MAX_VALUE - 1, 2);
+ }
+
+ @Test
+ public void checkedAdd_Valid() {
+ assertThat(TimeUtils.checkedAdd(1, 2)).isEqualTo(3);
+ assertThat(TimeUtils.checkedAdd(Integer.MAX_VALUE, Integer.MAX_VALUE))
+ .isEqualTo(2L * Integer.MAX_VALUE);
+ }
+}
diff --git a/api/src/test/java/io/opencensus/internal/UtilsTest.java b/api/src/test/java/io/opencensus/internal/UtilsTest.java
index dea7c843..983264f6 100644
--- a/api/src/test/java/io/opencensus/internal/UtilsTest.java
+++ b/api/src/test/java/io/opencensus/internal/UtilsTest.java
@@ -16,7 +16,6 @@
package io.opencensus.internal;
-import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -103,32 +102,4 @@ public final class UtilsTest {
assertFalse(Utils.equalsObjects(new Object(), null));
assertFalse(Utils.equalsObjects(new Object(), new Object()));
}
-
- @Test
- public void compareLongs() {
- assertThat(Utils.compareLongs(-1L, 1L)).isLessThan(0);
- assertThat(Utils.compareLongs(10L, 10L)).isEqualTo(0);
- assertThat(Utils.compareLongs(1L, 0L)).isGreaterThan(0);
- }
-
- @Test
- public void checkedAdd_TooLow() {
- thrown.expect(ArithmeticException.class);
- thrown.expectMessage("Long sum overflow: x=-9223372036854775807, y=-2");
- Utils.checkedAdd(Long.MIN_VALUE + 1, -2);
- }
-
- @Test
- public void checkedAdd_TooHigh() {
- thrown.expect(ArithmeticException.class);
- thrown.expectMessage("Long sum overflow: x=9223372036854775806, y=2");
- Utils.checkedAdd(Long.MAX_VALUE - 1, 2);
- }
-
- @Test
- public void checkedAdd_Valid() {
- assertThat(Utils.checkedAdd(1, 2)).isEqualTo(3);
- assertThat(Utils.checkedAdd(Integer.MAX_VALUE, Integer.MAX_VALUE))
- .isEqualTo(2L * Integer.MAX_VALUE);
- }
}