You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/25 13:15:15 UTC

(commons-lang) branch master updated (258406d3e -> be1081a06)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


    from 258406d3e Bump github/codeql-action from 3.25.5 to 3.25.6 (#1226)
     new 408b66081 More precise internal type
     new c6ce19a06 Add missing test assertions
     new be1081a06 Add missing test assertions

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/commons/lang3/time/DurationFormatUtils.java |  4 ++--
 .../apache/commons/lang3/time/DurationFormatUtilsTest.java | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)


(commons-lang) 03/03: Add missing test assertions

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit be1081a0661a6a82a6ca818c246f833b31639ec4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 25 08:04:57 2024 -0400

    Add missing test assertions
---
 .../org/apache/commons/lang3/time/DurationFormatUtilsTest.java     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
index 04e2bf318..5a0a3f6f1 100644
--- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
@@ -32,6 +32,7 @@ import java.util.Calendar;
 import java.util.TimeZone;
 
 import org.apache.commons.lang3.AbstractLangTest;
+import org.apache.commons.lang3.time.DurationFormatUtils.Token;
 import org.junit.jupiter.api.Test;
 import org.junitpioneer.jupiter.DefaultTimeZone;
 
@@ -644,8 +645,12 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
 
         // test failures in equals
         final DurationFormatUtils.Token token = createTokenWithCount(DurationFormatUtils.y, 4);
+        assertEquals(token, token);
+        assertEquals(token.hashCode(), token.hashCode());
         assertNotEquals(token, new Object(), "Token equal to non-Token class. ");
-        assertNotEquals(token, createTokenWithCount("", 1), "Token equal to Token with wrong value class. ");
+        final Token token2 = createTokenWithCount("", 1);
+        assertNotEquals(token, token2, "Token equal to Token with wrong value class. ");
+        assertNotEquals(token.hashCode(), token2.hashCode());
         assertNotEquals(token, createTokenWithCount(DurationFormatUtils.y, 1), "Token equal to Token with different count. ");
         final DurationFormatUtils.Token numToken = createTokenWithCount("1", 4);
         assertEquals(numToken, numToken, "Token with Number value not equal to itself. ");


(commons-lang) 01/03: More precise internal type

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 408b6608133359f03fc8d5b2c7cf4abd3813ebdd
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 25 07:59:39 2024 -0400

    More precise internal type
---
 .../java/org/apache/commons/lang3/time/DurationFormatUtils.java     | 4 ++--
 .../java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
index 417d2a592..2ecaaf70d 100644
--- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
@@ -98,7 +98,7 @@ public class DurationFormatUtils {
             return Stream.of(tokens).anyMatch(token -> token.getValue() == value);
         }
 
-        private final Object value;
+        private final CharSequence value;
         private int count;
         private int optionalIndex = -1;
 
@@ -109,7 +109,7 @@ public class DurationFormatUtils {
          * @param optional whether the token is optional
          * @param optionalIndex the index of the optional token within the pattern
          */
-        Token(final Object value, final boolean optional, final int optionalIndex) {
+        Token(final CharSequence value, final boolean optional, final int optionalIndex) {
             this.value = Objects.requireNonNull(value, "value");
             this.count = 1;
             if (optional) {
diff --git a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
index cbd4833e7..ee1d82f96 100644
--- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
@@ -82,7 +82,7 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
         }
     }
 
-    private DurationFormatUtils.Token createTokenWithCount(final Object value, final int count) {
+    private DurationFormatUtils.Token createTokenWithCount(final CharSequence value, final int count) {
         final DurationFormatUtils.Token token = new DurationFormatUtils.Token(value, false, -1);
         for (int i = 1; i < count; i++) {
             token.increment();
@@ -642,9 +642,9 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
         // test failures in equals
         final DurationFormatUtils.Token token = createTokenWithCount(DurationFormatUtils.y, 4);
         assertNotEquals(token, new Object(), "Token equal to non-Token class. ");
-        assertNotEquals(token, createTokenWithCount(new Object(), 1), "Token equal to Token with wrong value class. ");
+        assertNotEquals(token, createTokenWithCount("", 1), "Token equal to Token with wrong value class. ");
         assertNotEquals(token, createTokenWithCount(DurationFormatUtils.y, 1), "Token equal to Token with different count. ");
-        final DurationFormatUtils.Token numToken = createTokenWithCount(Integer.valueOf(1), 4);
+        final DurationFormatUtils.Token numToken = createTokenWithCount("1", 4);
         assertEquals(numToken, numToken, "Token with Number value not equal to itself. ");
     }
 


(commons-lang) 02/03: Add missing test assertions

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit c6ce19a068dc9e146aef8f80f31d050b38412106
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 25 08:01:43 2024 -0400

    Add missing test assertions
---
 .../java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java    | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
index ee1d82f96..04e2bf318 100644
--- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
@@ -84,8 +84,11 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
 
     private DurationFormatUtils.Token createTokenWithCount(final CharSequence value, final int count) {
         final DurationFormatUtils.Token token = new DurationFormatUtils.Token(value, false, -1);
+        // To help debugging, toString() on a Token should never blow up.
+        assertNotNull(token.toString());
         for (int i = 1; i < count; i++) {
             token.increment();
+            assertNotNull(token.toString());
         }
         return token;
     }