Merge "Fix error prone warnings" am: 8f15a06f5a am: 953a3b3276 am: 2f916f658c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1863056 Change-Id: I7dcffbcfbec8766bff1dfe0cef8c0421256803bf
This commit is contained in:
@@ -26,7 +26,7 @@ import java.time.Duration;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class Duration64 {
|
public final class Duration64 {
|
||||||
|
|
||||||
public static final Duration64 ZERO = new Duration64(0);
|
public static final Duration64 ZERO = new Duration64(0);
|
||||||
private final long mBits;
|
private final long mBits;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package android.net.sntp;
|
package android.net.sntp;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -113,7 +115,7 @@ public final class Timestamp64 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%08x.%08x", mEraSeconds, mFractionBits);
|
return TextUtils.formatSimple("%08x.%08x", mEraSeconds, mFractionBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the instant represented by this value in the specified NTP era. */
|
/** Returns the instant represented by this value in the specified NTP era. */
|
||||||
|
|||||||
@@ -21,13 +21,17 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class Duration64Test {
|
public class Duration64Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -21,13 +21,17 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class Timestamp64Test {
|
public class Timestamp64Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -191,6 +195,7 @@ public class Timestamp64Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("JavaInstantGetSecondsGetNano")
|
||||||
private static void assertInstantCreationOnlyFractionExact(
|
private static void assertInstantCreationOnlyFractionExact(
|
||||||
int fractionBits, long expectedNanos) {
|
int fractionBits, long expectedNanos) {
|
||||||
Timestamp64 timestamp64 = Timestamp64.fromComponents(0, fractionBits);
|
Timestamp64 timestamp64 = Timestamp64.fromComponents(0, fractionBits);
|
||||||
@@ -201,6 +206,7 @@ public class Timestamp64Test {
|
|||||||
assertEquals(expectedNanos, instant.getNano());
|
assertEquals(expectedNanos, instant.getNano());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("JavaInstantGetSecondsGetNano")
|
||||||
private static void assertNanosWithTruncationAllowed(long expectedNanos, Instant instant) {
|
private static void assertNanosWithTruncationAllowed(long expectedNanos, Instant instant) {
|
||||||
// Allow for < 1ns difference due to truncation.
|
// Allow for < 1ns difference due to truncation.
|
||||||
long actualNanos = instant.getNano();
|
long actualNanos = instant.getNano();
|
||||||
@@ -208,6 +214,7 @@ public class Timestamp64Test {
|
|||||||
actualNanos == expectedNanos || actualNanos == expectedNanos - 1);
|
actualNanos == expectedNanos || actualNanos == expectedNanos - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("JavaInstantGetSecondsGetNano")
|
||||||
@Test
|
@Test
|
||||||
public void testMillisRandomizationConstant() {
|
public void testMillisRandomizationConstant() {
|
||||||
// Mathematically, we can say that to represent 1000 different values, we need 10 binary
|
// Mathematically, we can say that to represent 1000 different values, we need 10 binary
|
||||||
|
|||||||
Reference in New Issue
Block a user