Procházet zdrojové kódy

Add validators

Issue 4253

Change-Id: Id5a06b7a2567cf5b23b7886f15faeb4f00a5cc34
Reviewed-on: http://gerrit.dmdirc.com/1456
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.5
Chris Smith před 13 roky
rodič
revize
fbd836e534
27 změnil soubory, kde provedl 1382 přidání a 0 odebrání
  1. 44
    0
      src/com/dmdirc/util/validators/FileNameValidator.java
  2. 45
    0
      src/com/dmdirc/util/validators/IdentValidator.java
  3. 45
    0
      src/com/dmdirc/util/validators/NicknameValidator.java
  4. 47
    0
      src/com/dmdirc/util/validators/NotEmptyValidator.java
  5. 90
    0
      src/com/dmdirc/util/validators/NumericalValidator.java
  6. 69
    0
      src/com/dmdirc/util/validators/OptionalValidator.java
  7. 48
    0
      src/com/dmdirc/util/validators/PermissiveValidator.java
  8. 41
    0
      src/com/dmdirc/util/validators/PortValidator.java
  9. 56
    0
      src/com/dmdirc/util/validators/RegexStringValidator.java
  10. 46
    0
      src/com/dmdirc/util/validators/RegexValidator.java
  11. 61
    0
      src/com/dmdirc/util/validators/StringLengthValidator.java
  12. 49
    0
      src/com/dmdirc/util/validators/URIValidator.java
  13. 69
    0
      src/com/dmdirc/util/validators/ValidationResponse.java
  14. 42
    0
      src/com/dmdirc/util/validators/Validator.java
  15. 65
    0
      src/com/dmdirc/util/validators/ValidatorChain.java
  16. 39
    0
      test/com/dmdirc/util/validators/FileNameValidatorTest.java
  17. 41
    0
      test/com/dmdirc/util/validators/IdentValidatorTest.java
  18. 41
    0
      test/com/dmdirc/util/validators/NicknameValidatorTest.java
  19. 40
    0
      test/com/dmdirc/util/validators/NotEmptyValidatorTest.java
  20. 76
    0
      test/com/dmdirc/util/validators/NumericalValidatorTest.java
  21. 63
    0
      test/com/dmdirc/util/validators/OptionalValidatorTest.java
  22. 36
    0
      test/com/dmdirc/util/validators/PermissiveValidatorTest.java
  23. 38
    0
      test/com/dmdirc/util/validators/PortValidatorTest.java
  24. 40
    0
      test/com/dmdirc/util/validators/RegexStringValidatorTest.java
  25. 39
    0
      test/com/dmdirc/util/validators/RegexValidatorTest.java
  26. 68
    0
      test/com/dmdirc/util/validators/StringLengthValidatorTest.java
  27. 44
    0
      test/com/dmdirc/util/validators/ValidatorChainTest.java

+ 44
- 0
src/com/dmdirc/util/validators/FileNameValidator.java Zobrazit soubor

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates filenames.
27
+ */
28
+public class FileNameValidator implements Validator<String> {
29
+
30
+    /** Filename regex. */
31
+    private static final String FILENAME_REGEX = "[A-Za-z0-9 \\-_!]+";
32
+    /** Failure reason. */
33
+    private static final String FAILURE_REASON = "Must be a valid filename";
34
+
35
+    /** {@inheritDoc} */
36
+    @Override
37
+    public ValidationResponse validate(final String object) {
38
+        if (object.matches(FILENAME_REGEX)) {
39
+            return new ValidationResponse();
40
+        } else {
41
+            return new ValidationResponse(FAILURE_REASON);
42
+        }
43
+    }
44
+}

+ 45
- 0
src/com/dmdirc/util/validators/IdentValidator.java Zobrazit soubor

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates idents.
27
+ */
28
+public class IdentValidator implements Validator<String> {
29
+
30
+    /** Ident regex. */
31
+    private static final String IDENT_REGEX = "[A-Za-z0-9\\[\\]{|}\\-\\^\\\\]*";
32
+    /** Failure reason. */
33
+    private static final String FAILURE_REASON = "Ident must only contain "
34
+            + "letters, numbers and []{}|-^\\.";
35
+
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public ValidationResponse validate(final String object) {
39
+        if (object.matches(IDENT_REGEX)) {
40
+            return new ValidationResponse();
41
+        } else {
42
+            return new ValidationResponse(FAILURE_REASON);
43
+        }
44
+    }
45
+}

+ 45
- 0
src/com/dmdirc/util/validators/NicknameValidator.java Zobrazit soubor

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates nicknames.
27
+ */
28
+public class NicknameValidator implements Validator<String> {
29
+
30
+    /** Nickname regex. */
31
+    private static final String NICKNAME_REGEX = "[A-Za-z0-9\\[\\]{|}\\-\\^\\\\\\`\\_]+";
32
+    /** Failure reason. */
33
+    private static final String FAILURE_REASON = "Nickname must only contain "
34
+            + "letters, numbers and []{}|-^\\.`_";
35
+
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public ValidationResponse validate(final String object) {
39
+        if (object.matches(NICKNAME_REGEX)) {
40
+            return new ValidationResponse();
41
+        } else {
42
+            return new ValidationResponse(FAILURE_REASON);
43
+        }
44
+    }
45
+}

+ 47
- 0
src/com/dmdirc/util/validators/NotEmptyValidator.java Zobrazit soubor

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validator checking the string is not empty.
27
+ */
28
+public class NotEmptyValidator implements Validator<String> {
29
+
30
+    /**
31
+     * A version number for this class. It should be changed whenever the class
32
+     * structure is changed (or anything else that would prevent serialized
33
+     * objects being unserialized with the new class).
34
+     */
35
+    private static final long serialVersionUID = 1;
36
+
37
+    /** {@inheritDoc} */
38
+    @Override
39
+    public ValidationResponse validate(final String object) {
40
+        if (object == null || object.isEmpty()) {
41
+            return new ValidationResponse("Cannot be an empty string.");
42
+        } else {
43
+            return new ValidationResponse();
44
+        }
45
+    }
46
+
47
+}

+ 90
- 0
src/com/dmdirc/util/validators/NumericalValidator.java Zobrazit soubor

@@ -0,0 +1,90 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates that a number is within certain bounds.
27
+ *
28
+ * @author chris
29
+ */
30
+public class NumericalValidator implements Validator<String> {
31
+
32
+    /** The minimum value for this number. */
33
+    protected final int min;
34
+
35
+    /** The maximum value for this number. */
36
+    protected final int max;
37
+
38
+    /**
39
+     * Creates a new numerical validator with the specified bounds.
40
+     *
41
+     * @param min The minimum value for the number, or -1 for unlimited.
42
+     * @param max The maximum value for the number, or -1 for unlimited.
43
+     */
44
+    public NumericalValidator(int min, int max) {
45
+        this.max = max == -1 ? Integer.MAX_VALUE : max;
46
+        this.min = min == -1 ? Integer.MIN_VALUE : min;
47
+        if (this.min > this.max) {
48
+            throw new IllegalArgumentException("min must be less than max.");
49
+        }
50
+    }
51
+
52
+    /**
53
+     * Retrieves the maximum value that this validator will allow.
54
+     *
55
+     * @return This validator's maximum value
56
+     */
57
+    public int getMax() {
58
+        return max;
59
+    }
60
+
61
+    /**
62
+     * Retrieves the minimum value that this validator will allow.
63
+     *
64
+     * @return This validator's minimum value
65
+     */
66
+    public int getMin() {
67
+        return min;
68
+    }
69
+
70
+    /** {@inheritDoc} */
71
+    @Override
72
+    public ValidationResponse validate(final String object) {
73
+        int intv;
74
+
75
+        try {
76
+            intv = Integer.parseInt(object);
77
+        } catch (NumberFormatException ex) {
78
+            return new ValidationResponse("Must be a valid number");
79
+        }
80
+
81
+        if (intv < min) {
82
+            return new ValidationResponse("Must be at least " + min);
83
+        } else if (intv > max) {
84
+            return new ValidationResponse("Must be at most " + max);
85
+        } else {
86
+            return new ValidationResponse();
87
+        }
88
+    }
89
+
90
+}

+ 69
- 0
src/com/dmdirc/util/validators/OptionalValidator.java Zobrazit soubor

@@ -0,0 +1,69 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates an optional setting in tandem with another validator.
27
+ */
28
+public class OptionalValidator implements Validator<String> {
29
+
30
+    /** The minimum value for this number. */
31
+    protected final Validator<String> validator;
32
+
33
+    /**
34
+     * Creates a new Optional validator.
35
+     *
36
+     * @param validator The validator for the setting's value, if present
37
+     */
38
+    public OptionalValidator(final Validator<String> validator) {
39
+        this.validator = validator;
40
+    }
41
+
42
+    /**
43
+     * Gets the secondary validator.
44
+     *
45
+     * @return Secondary validator
46
+     */
47
+    public Validator<String> getValidator() {
48
+        return validator;
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public ValidationResponse validate(final String object) {
54
+        final int colonIndex = object.indexOf(':');
55
+
56
+        if (colonIndex == -1) {
57
+            return new ValidationResponse("Must contain boolean int seperator.");
58
+        }
59
+
60
+        final String booleanv = object.substring(0, colonIndex);
61
+
62
+        if (!"true".equals(booleanv) && !"false".equals(booleanv)) {
63
+            return new ValidationResponse("Must be true or false.");
64
+        }
65
+
66
+        return validator.validate(object.substring(colonIndex + 1));
67
+    }
68
+
69
+}

+ 48
- 0
src/com/dmdirc/util/validators/PermissiveValidator.java Zobrazit soubor

@@ -0,0 +1,48 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.ValidationResponse;
25
+import com.dmdirc.util.validators.Validator;
26
+
27
+/**
28
+ * A validator that permits everything.
29
+ *
30
+ * @param <V> The type of data that this validator validates
31
+ * @author chris
32
+ */
33
+public class PermissiveValidator<V> implements Validator<V> {
34
+    
35
+    /**
36
+     * Creates a new instance of PermissiveValidator.
37
+     */
38
+    public PermissiveValidator() {
39
+        super();
40
+    }
41
+
42
+    /** {@inheritDoc} */
43
+    @Override
44
+    public ValidationResponse validate(final V object) {
45
+        return new ValidationResponse();
46
+    }
47
+
48
+}

+ 41
- 0
src/com/dmdirc/util/validators/PortValidator.java Zobrazit soubor

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+/**
25
+ * Validates a port number.
26
+ *
27
+ * @author chris
28
+ */
29
+public class PortValidator extends NumericalValidator {
30
+
31
+    /** The minimum port number. */
32
+    private static final int MIN_PORT = 1;
33
+
34
+    /** The maximum port number. */
35
+    private static final int MAX_PORT = 65535;
36
+
37
+    public PortValidator() {
38
+        super(MIN_PORT, MAX_PORT);
39
+    }
40
+
41
+}

+ 56
- 0
src/com/dmdirc/util/validators/RegexStringValidator.java Zobrazit soubor

@@ -0,0 +1,56 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Regex validator.
27
+ */
28
+public class RegexStringValidator implements Validator<String> {
29
+
30
+    /** Regex. */
31
+    private final String regex;
32
+    /** Failure reason. */
33
+    private final String failedReason;
34
+
35
+    /**
36
+     * Instantiates a new regex validator.
37
+     *
38
+     * @param regex Regex to validate text against
39
+     * @param failedReason Reason for validation failure
40
+     */
41
+    public RegexStringValidator(final String regex, final String failedReason) {
42
+        this.regex = regex;
43
+        this.failedReason = failedReason;
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public ValidationResponse validate(final String object) {
49
+        if (object.matches(regex)) {
50
+            return new ValidationResponse();
51
+        } else {
52
+            return new ValidationResponse(failedReason);
53
+        }
54
+    }
55
+
56
+}

+ 46
- 0
src/com/dmdirc/util/validators/RegexValidator.java Zobrazit soubor

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates a regular expression.
27
+ *
28
+ * @author chris
29
+ */
30
+public class RegexValidator implements Validator<String> {
31
+
32
+    /** {@inheritDoc} */
33
+    @Override
34
+    public ValidationResponse validate(final String object) {
35
+        try {
36
+            // Is there a proper way of doing this, as opposed to just seeing
37
+            // if it breaks?
38
+
39
+            "abc".matches(object);
40
+            return new ValidationResponse();
41
+        } catch (Exception ex) {
42
+            return new ValidationResponse(ex.getMessage());
43
+        }
44
+    }
45
+
46
+}

+ 61
- 0
src/com/dmdirc/util/validators/StringLengthValidator.java Zobrazit soubor

@@ -0,0 +1,61 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+/**
25
+ * Validates that the length of a string is within certain bounds.
26
+ * 
27
+ * @author chris
28
+ */
29
+public class StringLengthValidator implements Validator<String> {
30
+    
31
+    /** The minimum string length. */
32
+    protected final int min;
33
+    
34
+    /** The maximum string length. */
35
+    protected final int max;
36
+
37
+    /**
38
+     * Creates a new string length validator that requires a string be between
39
+     * the specified min/max length.
40
+     *
41
+     * @param min The minimum length of the string, or -1 for unlimited.
42
+     * @param max The maximum length of the string, or -1 for unlimited.
43
+     */
44
+    public StringLengthValidator(final int min, final int max) {
45
+        this.min = min;
46
+        this.max = max;
47
+    }
48
+
49
+    /** {@inheritDoc} */
50
+    @Override
51
+    public ValidationResponse validate(final String object) {
52
+        if (object.length() < min && min != -1) {
53
+            return new ValidationResponse("Must be at least " + min + " characters long");
54
+        } else if (object.length() > max && max != -1) {
55
+            return new ValidationResponse("Must be at most " + max + " characters long");
56
+        } else {
57
+            return new ValidationResponse();
58
+        }
59
+    }
60
+
61
+}

+ 49
- 0
src/com/dmdirc/util/validators/URIValidator.java Zobrazit soubor

@@ -0,0 +1,49 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import java.net.URI;
26
+import java.net.URISyntaxException;
27
+
28
+/**
29
+ * Validates a string to see if it compiles to a URI.
30
+ */
31
+public class URIValidator implements Validator<String> {
32
+
33
+    /** {@inheritDoc} */
34
+    @Override
35
+    public ValidationResponse validate(final String object) {
36
+        ValidationResponse result;
37
+        try {
38
+            final URI uri = new URI(object);
39
+            if (uri.getHost() == null || uri.getHost().isEmpty()) {
40
+                result = new ValidationResponse("Address requires a hostname.");
41
+            } else {
42
+                result = new ValidationResponse();
43
+            }
44
+        } catch (URISyntaxException ex) {
45
+            result = new ValidationResponse(ex.getReason());
46
+        }
47
+        return result;
48
+    }
49
+}

+ 69
- 0
src/com/dmdirc/util/validators/ValidationResponse.java Zobrazit soubor

@@ -0,0 +1,69 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+/**
25
+ * Describes the response from a Validator. The response may be either positive
26
+ * or negative. Negative responses have an associated failure reason.
27
+ *
28
+ * @author chris
29
+ */
30
+public class ValidationResponse {
31
+
32
+    /** The failure reason, or null if the validation passed. */
33
+    private final String failure;
34
+
35
+    /**
36
+     * Creates a new ValidationResponse for a positive response.
37
+     */
38
+    public ValidationResponse() {
39
+        this(null);
40
+    }
41
+
42
+    /**
43
+     * Creates a new ValidationResponse for a negative response.
44
+     *
45
+     * @param failure The reason for the negative response.
46
+     */
47
+    public ValidationResponse(final String failure) {
48
+        this.failure = failure;
49
+    }
50
+
51
+    /**
52
+     * Determines whether or not this response indicates that a failure occured.
53
+     *
54
+     * @return True if a failure occured, false otherwise.
55
+     */
56
+    public boolean isFailure() {
57
+        return failure != null;
58
+    }
59
+
60
+    /**
61
+     * Retrieves the reason for the validation failure.
62
+     *
63
+     * @return The reason for the validation failure.
64
+     */
65
+    public String getFailureReason() {
66
+        return failure;
67
+    }
68
+
69
+}

+ 42
- 0
src/com/dmdirc/util/validators/Validator.java Zobrazit soubor

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validator interface.
27
+ *
28
+ * @param <V> Type to validate
29
+ */
30
+public interface Validator<V> {
31
+
32
+    /**
33
+     * Validates the object.
34
+     *
35
+     * @param object Object to validate
36
+     *
37
+     * @return A validation response indicating the success/failure of the
38
+     * validation
39
+     */
40
+    ValidationResponse validate(final V object);
41
+
42
+}

+ 65
- 0
src/com/dmdirc/util/validators/ValidatorChain.java Zobrazit soubor

@@ -0,0 +1,65 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import java.util.ArrayList;
26
+import java.util.List;
27
+
28
+/**
29
+ * Allows multiple validators to be chained together.
30
+ *
31
+ * @param <A> The type of class that this chain validates
32
+ * @author chris
33
+ */
34
+public class ValidatorChain<A> implements Validator<A> {
35
+
36
+    /** A list of validators to use. */
37
+    private final List<Validator<A>> validatorList
38
+            = new ArrayList<Validator<A>>();
39
+
40
+    /**
41
+     * Creates a new validator chain containing the specified validators.
42
+     *
43
+     * @param validators The validators to be used in this chain.
44
+     */
45
+    public ValidatorChain(final Validator<A> ... validators) {
46
+        for (Validator<A> validator : validators) {
47
+            validatorList.add(validator);
48
+        }
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public ValidationResponse validate(final A object) {
54
+        for (Validator<A> validator : validatorList) {
55
+            final ValidationResponse res = validator.validate(object);
56
+
57
+            if (res.isFailure()) {
58
+                return res;
59
+            }
60
+        }
61
+
62
+        return new ValidationResponse();
63
+    }
64
+
65
+}

+ 39
- 0
test/com/dmdirc/util/validators/FileNameValidatorTest.java Zobrazit soubor

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.FileNameValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class FileNameValidatorTest {
30
+
31
+    @Test
32
+    public void testValidate() {
33
+        final FileNameValidator rv = new FileNameValidator();
34
+        
35
+        assertTrue(rv.validate("/foo").isFailure());
36
+        assertFalse(rv.validate("filename").isFailure());
37
+    }
38
+
39
+}

+ 41
- 0
test/com/dmdirc/util/validators/IdentValidatorTest.java Zobrazit soubor

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.IdentValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class IdentValidatorTest {
30
+
31
+    @Test
32
+    public void testPass() {
33
+        assertTrue(new IdentValidator().validate("foo bar").isFailure());
34
+    }
35
+
36
+    @Test
37
+    public void testFail() {
38
+        assertFalse(new IdentValidator().validate("foo[]bar").isFailure());
39
+    }
40
+
41
+}

+ 41
- 0
test/com/dmdirc/util/validators/NicknameValidatorTest.java Zobrazit soubor

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.NicknameValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class NicknameValidatorTest {
30
+
31
+    @Test
32
+    public void testPass() {
33
+        assertTrue(new NicknameValidator().validate("foo bar").isFailure());
34
+    }
35
+
36
+    @Test
37
+    public void testFail() {
38
+        assertFalse(new NicknameValidator().validate("foo[]bar").isFailure());
39
+    }
40
+
41
+}

+ 40
- 0
test/com/dmdirc/util/validators/NotEmptyValidatorTest.java Zobrazit soubor

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.NotEmptyValidator;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class NotEmptyValidatorTest {
29
+
30
+    @Test
31
+    public void testValidate() {
32
+        final NotEmptyValidator nev = new NotEmptyValidator();
33
+        
34
+        assertTrue(nev.validate("").isFailure());
35
+        assertTrue(nev.validate("").getFailureReason().indexOf("empty") > -1);
36
+        assertFalse(nev.validate("moo").isFailure());
37
+        assertFalse(nev.validate(" ").isFailure());
38
+    }
39
+
40
+}

+ 76
- 0
test/com/dmdirc/util/validators/NumericalValidatorTest.java Zobrazit soubor

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.ValidationResponse;
25
+import com.dmdirc.util.validators.NumericalValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class NumericalValidatorTest {
30
+
31
+    @Test
32
+    public void testGetMax() {
33
+        assertEquals(10, new NumericalValidator(1, 10).getMax());
34
+        assertEquals(Integer.MAX_VALUE, new NumericalValidator(1, -1).getMax());
35
+    }
36
+
37
+    @Test
38
+    public void testGetMin() {
39
+        assertEquals(1, new NumericalValidator(1, 10).getMin());
40
+        assertEquals(Integer.MIN_VALUE, new NumericalValidator(-1, 10).getMin());
41
+    }
42
+
43
+    @Test
44
+    public void testNAN() {
45
+        final ValidationResponse vr = new NumericalValidator(3, 5).validate("foo");
46
+        
47
+        assertTrue(vr.isFailure());
48
+        assertTrue(vr.getFailureReason().indexOf("number") > -1);
49
+    }
50
+    
51
+    @Test
52
+    public void testMin() {
53
+        final NumericalValidator nv1 = new NumericalValidator(-1, -1);
54
+        final NumericalValidator nv2 = new NumericalValidator(-5, -1);
55
+        
56
+        assertFalse(nv1.validate("-5").isFailure());
57
+        assertFalse(nv2.validate("-5").isFailure());
58
+        assertFalse(nv2.validate("-4").isFailure());
59
+        assertFalse(nv2.validate("10").isFailure());
60
+        assertTrue(nv2.validate("-6").isFailure());
61
+    }
62
+    
63
+    @Test
64
+    public void testMax() {
65
+        final NumericalValidator nv1 = new NumericalValidator(-1, -1);
66
+        final NumericalValidator nv2 = new NumericalValidator(-1, 10);
67
+        
68
+        assertFalse(nv1.validate("-5").isFailure());
69
+        assertFalse(nv1.validate("50").isFailure());
70
+        assertFalse(nv2.validate("-5").isFailure());
71
+        assertFalse(nv2.validate("-4").isFailure());
72
+        assertFalse(nv2.validate("10").isFailure());
73
+        assertTrue(nv2.validate("11").isFailure());
74
+    }    
75
+
76
+}

+ 63
- 0
test/com/dmdirc/util/validators/OptionalValidatorTest.java Zobrazit soubor

@@ -0,0 +1,63 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.OptionalValidator;
26
+import com.dmdirc.util.validators.ValidationResponse;
27
+import com.dmdirc.util.validators.StringLengthValidator;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class OptionalValidatorTest {
32
+
33
+    @Test
34
+    public void testNoSeparator() {
35
+        final ValidationResponse res = new OptionalValidator(null).validate("foo");
36
+        assertTrue(res.isFailure());
37
+        assertTrue(res.getFailureReason().contains("boolean"));
38
+    }
39
+
40
+    @Test
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"));
46
+    }
47
+
48
+    @Test
49
+    public void testTrueValidation() {
50
+        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(0, 3))
51
+                .validate("true:bar");
52
+        assertFalse(res.isFailure());
53
+    }
54
+
55
+    @Test
56
+    public void testFalseValidation() {
57
+        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(0, 2))
58
+                .validate("true:bar");
59
+        assertTrue(res.isFailure());
60
+        assertTrue(res.getFailureReason().contains("at most 2"));
61
+    }
62
+
63
+}

+ 36
- 0
test/com/dmdirc/util/validators/PermissiveValidatorTest.java Zobrazit soubor

@@ -0,0 +1,36 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.PermissiveValidator;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class PermissiveValidatorTest {
29
+
30
+    @Test
31
+    public void testValidate() {
32
+        assertFalse(new PermissiveValidator<String>().validate("abc").isFailure());
33
+        assertFalse(new PermissiveValidator<String>().validate(null).isFailure());
34
+    }
35
+
36
+}

+ 38
- 0
test/com/dmdirc/util/validators/PortValidatorTest.java Zobrazit soubor

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.PortValidator;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class PortValidatorTest {
29
+
30
+    @Test
31
+    public void testBounds() {
32
+        final PortValidator pv = new PortValidator();
33
+        
34
+        assertEquals(1, pv.getMin());
35
+        assertEquals(65535, pv.getMax());
36
+    }
37
+
38
+}

+ 40
- 0
test/com/dmdirc/util/validators/RegexStringValidatorTest.java Zobrazit soubor

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.RegexStringValidator;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class RegexStringValidatorTest {
29
+
30
+    @Test
31
+    public void testValidate() {
32
+        final String reason = "abc 123";
33
+        final RegexStringValidator rv = new RegexStringValidator("[0-9]{5}", reason);
34
+        
35
+        assertTrue(rv.validate("abc").isFailure());
36
+        assertEquals(reason, rv.validate("abc").getFailureReason());
37
+        assertFalse(rv.validate("55555").isFailure());
38
+    }
39
+
40
+}

+ 39
- 0
test/com/dmdirc/util/validators/RegexValidatorTest.java Zobrazit soubor

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.RegexValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class RegexValidatorTest {
30
+
31
+    @Test
32
+    public void testValidate() {
33
+        final RegexValidator rv = new RegexValidator();
34
+        
35
+        assertTrue(rv.validate("****").isFailure());
36
+        assertFalse(rv.validate("[a-z]").isFailure());
37
+    }
38
+
39
+}

+ 68
- 0
test/com/dmdirc/util/validators/StringLengthValidatorTest.java Zobrazit soubor

@@ -0,0 +1,68 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.util.validators;
23
+
24
+import com.dmdirc.util.validators.StringLengthValidator;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class StringLengthValidatorTest {
29
+
30
+    @Test
31
+    public void testUnlimited() {
32
+        final StringLengthValidator slv = new StringLengthValidator(-1, 10);
33
+        
34
+        assertFalse(slv.validate("123").isFailure());
35
+        assertFalse(slv.validate("").isFailure());
36
+        assertFalse(slv.validate("123456789").isFailure());
37
+        
38
+        final StringLengthValidator slv2 = new StringLengthValidator(0, -1);
39
+        
40
+        assertFalse(slv2.validate("123456789").isFailure());
41
+        assertFalse(slv2.validate("1").isFailure());
42
+    }
43
+    
44
+    @Test
45
+    public void testMinimum() {
46
+        final StringLengthValidator slv = new StringLengthValidator(5, 100);
47
+        
48
+        assertTrue(slv.validate("").isFailure());
49
+        assertTrue(slv.validate("123").isFailure());
50
+        assertTrue(slv.validate("1234").isFailure());
51
+        assertTrue(slv.validate("1234").getFailureReason().indexOf("at least 5") > -1);
52
+        assertFalse(slv.validate("12345").isFailure());
53
+        assertFalse(slv.validate("12345789").isFailure());
54
+    }
55
+    
56
+    @Test
57
+    public void testMaximum() {
58
+        final StringLengthValidator slv = new StringLengthValidator(0, 3);
59
+        
60
+        assertFalse(slv.validate("").isFailure());
61
+        assertFalse(slv.validate("12").isFailure());
62
+        assertFalse(slv.validate("123").isFailure());
63
+        assertTrue(slv.validate("1234").isFailure());
64
+        assertTrue(slv.validate("1234").getFailureReason().indexOf("at most 3") > -1);
65
+        assertTrue(slv.validate("12345").isFailure());
66
+    }    
67
+
68
+}

+ 44
- 0
test/com/dmdirc/util/validators/ValidatorChainTest.java Zobrazit soubor

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+import com.dmdirc.util.validators.ValidatorChain;
26
+import com.dmdirc.util.validators.RegexStringValidator;
27
+import com.dmdirc.util.validators.NotEmptyValidator;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class ValidatorChainTest {
32
+
33
+    @Test
34
+    public void testValidate() {
35
+        @SuppressWarnings("unchecked")
36
+        final ValidatorChain<String> chain = new ValidatorChain<String>(
37
+                new NotEmptyValidator(), new RegexStringValidator("[a-z]*", "abc"));
38
+        
39
+        assertTrue(chain.validate("").isFailure());
40
+        assertTrue(chain.validate("__").isFailure());
41
+        assertFalse(chain.validate("abc").isFailure());
42
+    }
43
+
44
+}

Načítá se…
Zrušit
Uložit