commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [lang] Add tests with a better comparator. Closes #132
Date Wed, 20 Apr 2016 00:54:07 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master 833885c29 -> 3f796bf74


Add tests with a better comparator. Closes #132

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/3f796bf7
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/3f796bf7
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/3f796bf7

Branch: refs/heads/master
Commit: 3f796bf74666ff9a4a6d31f10dbde4fd5e837d6a
Parents: 833885c
Author: ggregory <ggregory@apache.org>
Authored: Tue Apr 19 17:54:04 2016 -0700
Committer: ggregory <ggregory@apache.org>
Committed: Tue Apr 19 17:54:04 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/commons/lang3/RangeTest.java | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/3f796bf7/src/test/java/org/apache/commons/lang3/RangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/RangeTest.java b/src/test/java/org/apache/commons/lang3/RangeTest.java
index 871f085..2163347 100644
--- a/src/test/java/org/apache/commons/lang3/RangeTest.java
+++ b/src/test/java/org/apache/commons/lang3/RangeTest.java
@@ -96,13 +96,18 @@ public class RangeTest {
 
     @Test
     public void testBetweenWithCompare(){
-        // TODO add tests with a better comparator
         final Comparator<Integer> c = new Comparator<Integer>(){
             @Override
             public int compare(final Integer o1, final Integer o2) {
                 return 0; // all integers are equal
             }
         };
+        final Comparator<String> lengthComp = new Comparator<String>(){
+            @Override
+            public int compare(final String str1, final String str2) {
+                return str1.length() - str2.length();
+            }
+        };
         Range<Integer> rb = Range.between(-10,20);
         assertFalse("should not contain null",rb.contains(null));
         assertTrue("should contain 10",rb.contains(10));
@@ -115,6 +120,18 @@ public class RangeTest {
         assertTrue("should contain -10",rb.contains(-10));
         assertTrue("should contain 21",rb.contains(21));
         assertTrue("should contain -11",rb.contains(-11));
+        Range<String> rbstr = Range.between("house", "i");
+        assertFalse("should not contain null",rbstr.contains(null));
+        assertTrue("should contain house",rbstr.contains("house"));
+        assertTrue("should contain i",rbstr.contains("i"));
+        assertFalse("should not contain hose",rbstr.contains("hose"));
+        assertFalse("should not contain ice",rbstr.contains("ice"));
+        rbstr = Range.between("house", "i", lengthComp);
+        assertFalse("should not contain null",rbstr.contains(null));
+        assertTrue("should contain house",rbstr.contains("house"));
+        assertTrue("should contain i",rbstr.contains("i"));
+        assertFalse("should not contain houses",rbstr.contains("houses"));
+        assertFalse("should not contain ''",rbstr.contains(""));
     }
 
     //-----------------------------------------------------------------------


Mime
View raw message