Browse Source

OptionalValidator no longer fails valid settings

Change-Id: I84d88575fd48f11ef1236fcbe1d137ac5bbbc920
Reviewed-on: http://gerrit.dmdirc.com/1568
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5
Chris Smith 13 years ago
parent
commit
9ba9a54d56

+ 4
- 4
src/com/dmdirc/util/validators/OptionalValidator.java View File

54
         final int colonIndex = object.indexOf(':');
54
         final int colonIndex = object.indexOf(':');
55
 
55
 
56
         if (colonIndex == -1) {
56
         if (colonIndex == -1) {
57
-            return new ValidationResponse("Must contain boolean int seperator.");
57
+            return validator.validate(object);
58
         }
58
         }
59
 
59
 
60
         final String booleanv = object.substring(0, colonIndex);
60
         final String booleanv = object.substring(0, colonIndex);
61
 
61
 
62
-        if (!"true".equals(booleanv) && !"false".equals(booleanv)) {
63
-            return new ValidationResponse("Must be true or false.");
62
+        if ("true".equals(booleanv) || "false".equals(booleanv)) {
63
+            return validator.validate(object.substring(colonIndex + 1));
64
         }
64
         }
65
 
65
 
66
-        return validator.validate(object.substring(colonIndex + 1));
66
+        return validator.validate(object);
67
     }
67
     }
68
 
68
 
69
 }
69
 }

+ 6
- 7
test/com/dmdirc/util/validators/OptionalValidatorTest.java View File

32
 
32
 
33
     @Test
33
     @Test
34
     public void testNoSeparator() {
34
     public void testNoSeparator() {
35
-        final ValidationResponse res = new OptionalValidator(null).validate("foo");
36
-        assertTrue(res.isFailure());
37
-        assertTrue(res.getFailureReason().contains("boolean"));
35
+        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(0, 3))
36
+                .validate("foo");
37
+        assertFalse(res.isFailure());
38
     }
38
     }
39
 
39
 
40
     @Test
40
     @Test
41
     public void testIllegalPrefix() {
41
     public void testIllegalPrefix() {
42
-        final ValidationResponse res = new OptionalValidator(null).validate("foo:bar");
43
-        assertTrue(res.isFailure());
44
-        assertTrue(res.getFailureReason().contains("true"));
45
-        assertTrue(res.getFailureReason().contains("false"));
42
+        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(6, 7))
43
+                .validate("foo:bar");
44
+        assertFalse(res.isFailure());
46
     }
45
     }
47
 
46
 
48
     @Test
47
     @Test

Loading…
Cancel
Save