From 58fb2ebaba130c77519a61d2cceb3c667c64c843 Mon Sep 17 00:00:00 2001 From: Google Java Core Libraries Date: Fri, 27 Dec 2024 07:31:33 -0800 Subject: [PATCH] Adding test scenarios related to leading and trailing spaces when parsing string to Long PiperOrigin-RevId: 710059358 --- .../test/com/google/common/primitives/LongsTest.java | 3 +++ guava-tests/test/com/google/common/primitives/LongsTest.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/android/guava-tests/test/com/google/common/primitives/LongsTest.java b/android/guava-tests/test/com/google/common/primitives/LongsTest.java index a86f8aca965e..9f4bfd562e56 100644 --- a/android/guava-tests/test/com/google/common/primitives/LongsTest.java +++ b/android/guava-tests/test/com/google/common/primitives/LongsTest.java @@ -648,6 +648,9 @@ public void testTryParse() { assertThat(Longs.tryParse("-")).isNull(); assertThat(Longs.tryParse("+1")).isNull(); assertThat(Longs.tryParse("999999999999999999999999")).isNull(); + assertThat(Longs.tryParse(" ")).isNull(); + assertThat(Longs.tryParse("1 ")).isNull(); + assertThat(Longs.tryParse(" 1")).isNull(); assertWithMessage("Max long + 1") .that(Longs.tryParse(BigInteger.valueOf(MAX_VALUE).add(BigInteger.ONE).toString())) .isNull(); diff --git a/guava-tests/test/com/google/common/primitives/LongsTest.java b/guava-tests/test/com/google/common/primitives/LongsTest.java index a86f8aca965e..9f4bfd562e56 100644 --- a/guava-tests/test/com/google/common/primitives/LongsTest.java +++ b/guava-tests/test/com/google/common/primitives/LongsTest.java @@ -648,6 +648,9 @@ public void testTryParse() { assertThat(Longs.tryParse("-")).isNull(); assertThat(Longs.tryParse("+1")).isNull(); assertThat(Longs.tryParse("999999999999999999999999")).isNull(); + assertThat(Longs.tryParse(" ")).isNull(); + assertThat(Longs.tryParse("1 ")).isNull(); + assertThat(Longs.tryParse(" 1")).isNull(); assertWithMessage("Max long + 1") .that(Longs.tryParse(BigInteger.valueOf(MAX_VALUE).add(BigInteger.ONE).toString())) .isNull();