Ver código fonte

Move validators out of config.prefs.validator

Fixes issue 4253

Change-Id: Ibb46a6a1ba5c62d525b65f55d39632b82e335539
Reviewed-on: http://gerrit.dmdirc.com/1455
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.5b1
Chris Smith 13 anos atrás
pai
commit
10ad8f480d
43 arquivos alterados com 33 adições e 1382 exclusões
  1. 3
    1
      src/com/dmdirc/actions/validators/ActionGroupValidator.java
  2. 3
    1
      src/com/dmdirc/actions/validators/ActionNameValidator.java
  3. 3
    1
      src/com/dmdirc/actions/validators/ConditionRuleValidator.java
  4. 1
    1
      src/com/dmdirc/commandparser/commands/ValidatingCommand.java
  5. 1
    1
      src/com/dmdirc/commandparser/commands/chat/Me.java
  6. 3
    1
      src/com/dmdirc/commandparser/validators/CommandNameValidator.java
  7. 2
    2
      src/com/dmdirc/config/prefs/PreferencesManager.java
  8. 2
    2
      src/com/dmdirc/config/prefs/PreferencesSetting.java
  9. 0
    44
      src/com/dmdirc/config/prefs/validator/FileNameValidator.java
  10. 0
    45
      src/com/dmdirc/config/prefs/validator/IdentValidator.java
  11. 0
    45
      src/com/dmdirc/config/prefs/validator/NicknameValidator.java
  12. 0
    47
      src/com/dmdirc/config/prefs/validator/NotEmptyValidator.java
  13. 0
    90
      src/com/dmdirc/config/prefs/validator/NumericalValidator.java
  14. 0
    69
      src/com/dmdirc/config/prefs/validator/OptionalValidator.java
  15. 0
    45
      src/com/dmdirc/config/prefs/validator/PermissiveValidator.java
  16. 0
    41
      src/com/dmdirc/config/prefs/validator/PortValidator.java
  17. 0
    56
      src/com/dmdirc/config/prefs/validator/RegexStringValidator.java
  18. 0
    46
      src/com/dmdirc/config/prefs/validator/RegexValidator.java
  19. 0
    61
      src/com/dmdirc/config/prefs/validator/StringLengthValidator.java
  20. 0
    49
      src/com/dmdirc/config/prefs/validator/URIValidator.java
  21. 0
    69
      src/com/dmdirc/config/prefs/validator/ValidationResponse.java
  22. 0
    42
      src/com/dmdirc/config/prefs/validator/Validator.java
  23. 0
    65
      src/com/dmdirc/config/prefs/validator/ValidatorChain.java
  24. 3
    1
      src/com/dmdirc/config/validators/URLProtocolValidator.java
  25. 1
    1
      src/com/dmdirc/plugins/Plugin.java
  26. 1
    1
      src/com/dmdirc/plugins/PluginInfo.java
  27. 1
    1
      src/com/dmdirc/ui/input/InputHandler.java
  28. 2
    1
      test/com/dmdirc/actions/validators/ActionGroupValidatorTest.java
  29. 3
    1
      test/com/dmdirc/actions/validators/ConditionRuleValidatorTest.java
  30. 3
    3
      test/com/dmdirc/config/prefs/PreferencesSettingTest.java
  31. 0
    38
      test/com/dmdirc/config/prefs/validator/FileNameValidatorTest.java
  32. 0
    40
      test/com/dmdirc/config/prefs/validator/IdentValidatorTest.java
  33. 0
    40
      test/com/dmdirc/config/prefs/validator/NicknameValidatorTest.java
  34. 0
    39
      test/com/dmdirc/config/prefs/validator/NotEmptyValidatorTest.java
  35. 0
    74
      test/com/dmdirc/config/prefs/validator/NumericalValidatorTest.java
  36. 0
    60
      test/com/dmdirc/config/prefs/validator/OptionalValidatorTest.java
  37. 0
    35
      test/com/dmdirc/config/prefs/validator/PermissiveValidatorTest.java
  38. 0
    37
      test/com/dmdirc/config/prefs/validator/PortValidatorTest.java
  39. 0
    39
      test/com/dmdirc/config/prefs/validator/RegexStringValidatorTest.java
  40. 0
    38
      test/com/dmdirc/config/prefs/validator/RegexValidatorTest.java
  41. 0
    67
      test/com/dmdirc/config/prefs/validator/StringLengthValidatorTest.java
  42. 0
    41
      test/com/dmdirc/config/prefs/validator/ValidatorChainTest.java
  43. 1
    1
      test/com/dmdirc/config/validators/URLProtocolValidatorTest.java

src/com/dmdirc/config/prefs/validator/ActionGroupValidator.java → src/com/dmdirc/actions/validators/ActionGroupValidator.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.actions.validators;
24 24
 
25
+import com.dmdirc.util.validators.ValidationResponse;
26
+import com.dmdirc.util.validators.Validator;
25 27
 import com.dmdirc.actions.ActionManager;
26 28
 
27 29
 /**

src/com/dmdirc/config/prefs/validator/ActionNameValidator.java → src/com/dmdirc/actions/validators/ActionNameValidator.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.actions.validators;
24 24
 
25
+import com.dmdirc.util.validators.ValidationResponse;
26
+import com.dmdirc.util.validators.Validator;
25 27
 import com.dmdirc.actions.Action;
26 28
 import com.dmdirc.actions.ActionGroup;
27 29
 

src/com/dmdirc/config/prefs/validator/ConditionRuleValidator.java → src/com/dmdirc/actions/validators/ConditionRuleValidator.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.actions.validators;
24 24
 
25
+import com.dmdirc.util.validators.ValidationResponse;
26
+import com.dmdirc.util.validators.Validator;
25 27
 import com.dmdirc.actions.ConditionTree;
26 28
 
27 29
 /**

+ 1
- 1
src/com/dmdirc/commandparser/commands/ValidatingCommand.java Ver arquivo

@@ -22,7 +22,7 @@
22 22
 package com.dmdirc.commandparser.commands;
23 23
 
24 24
 import com.dmdirc.commandparser.CommandArguments;
25
-import com.dmdirc.config.prefs.validator.ValidationResponse;
25
+import com.dmdirc.util.validators.ValidationResponse;
26 26
 import com.dmdirc.ui.interfaces.InputWindow;
27 27
 
28 28
 /**

+ 1
- 1
src/com/dmdirc/commandparser/commands/chat/Me.java Ver arquivo

@@ -32,7 +32,7 @@ import com.dmdirc.commandparser.commands.Command;
32 32
 import com.dmdirc.commandparser.commands.ValidatingCommand;
33 33
 import com.dmdirc.commandparser.commands.context.ChatCommandContext;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35
-import com.dmdirc.config.prefs.validator.ValidationResponse;
35
+import com.dmdirc.util.validators.ValidationResponse;
36 36
 import com.dmdirc.ui.interfaces.InputWindow;
37 37
 
38 38
 /**

src/com/dmdirc/config/prefs/validator/CommandNameValidator.java → src/com/dmdirc/commandparser/validators/CommandNameValidator.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.commandparser.validators;
24 24
 
25
+import com.dmdirc.util.validators.RegexStringValidator;
26
+import com.dmdirc.util.validators.ValidatorChain;
25 27
 import com.dmdirc.commandparser.CommandManager;
26 28
 import java.util.regex.Pattern;
27 29
 

+ 2
- 2
src/com/dmdirc/config/prefs/PreferencesManager.java Ver arquivo

@@ -25,8 +25,8 @@ package com.dmdirc.config.prefs;
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28
-import com.dmdirc.config.prefs.validator.NumericalValidator;
29
-import com.dmdirc.config.prefs.validator.OptionalValidator;
28
+import com.dmdirc.util.validators.NumericalValidator;
29
+import com.dmdirc.util.validators.OptionalValidator;
30 30
 import com.dmdirc.plugins.PluginManager;
31 31
 import com.dmdirc.plugins.Service;
32 32
 import com.dmdirc.util.ListenerList;

+ 2
- 2
src/com/dmdirc/config/prefs/PreferencesSetting.java Ver arquivo

@@ -22,8 +22,8 @@
22 22
 package com.dmdirc.config.prefs;
23 23
 
24 24
 import com.dmdirc.config.IdentityManager;
25
-import com.dmdirc.config.prefs.validator.PermissiveValidator;
26
-import com.dmdirc.config.prefs.validator.Validator;
25
+import com.dmdirc.util.validators.PermissiveValidator;
26
+import com.dmdirc.util.validators.Validator;
27 27
 
28 28
 import java.util.ArrayList;
29 29
 import java.util.HashMap;

+ 0
- 44
src/com/dmdirc/config/prefs/validator/FileNameValidator.java Ver arquivo

@@ -1,44 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 45
src/com/dmdirc/config/prefs/validator/IdentValidator.java Ver arquivo

@@ -1,45 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 45
src/com/dmdirc/config/prefs/validator/NicknameValidator.java Ver arquivo

@@ -1,45 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 47
src/com/dmdirc/config/prefs/validator/NotEmptyValidator.java Ver arquivo

@@ -1,47 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 90
src/com/dmdirc/config/prefs/validator/NumericalValidator.java Ver arquivo

@@ -1,90 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 69
src/com/dmdirc/config/prefs/validator/OptionalValidator.java Ver arquivo

@@ -1,69 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 45
src/com/dmdirc/config/prefs/validator/PermissiveValidator.java Ver arquivo

@@ -1,45 +0,0 @@
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.config.prefs.validator;
23
-
24
-/**
25
- * A validator that permits everything.
26
- *
27
- * @param <V> The type of data that this validator validates
28
- * @author chris
29
- */
30
-public class PermissiveValidator<V> implements Validator<V> {
31
-    
32
-    /**
33
-     * Creates a new instance of PermissiveValidator.
34
-     */
35
-    public PermissiveValidator() {
36
-        super();
37
-    }
38
-
39
-    /** {@inheritDoc} */
40
-    @Override
41
-    public ValidationResponse validate(final V object) {
42
-        return new ValidationResponse();
43
-    }
44
-
45
-}

+ 0
- 41
src/com/dmdirc/config/prefs/validator/PortValidator.java Ver arquivo

@@ -1,41 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 56
src/com/dmdirc/config/prefs/validator/RegexStringValidator.java Ver arquivo

@@ -1,56 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 46
src/com/dmdirc/config/prefs/validator/RegexValidator.java Ver arquivo

@@ -1,46 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 61
src/com/dmdirc/config/prefs/validator/StringLengthValidator.java Ver arquivo

@@ -1,61 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 49
src/com/dmdirc/config/prefs/validator/URIValidator.java Ver arquivo

@@ -1,49 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 69
src/com/dmdirc/config/prefs/validator/ValidationResponse.java Ver arquivo

@@ -1,69 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 42
src/com/dmdirc/config/prefs/validator/Validator.java Ver arquivo

@@ -1,42 +0,0 @@
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.config.prefs.validator;
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
-}

+ 0
- 65
src/com/dmdirc/config/prefs/validator/ValidatorChain.java Ver arquivo

@@ -1,65 +0,0 @@
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.config.prefs.validator;
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
-}

src/com/dmdirc/config/prefs/validator/URLProtocolValidator.java → src/com/dmdirc/config/validators/URLProtocolValidator.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.config.validators;
24 24
 
25
+import com.dmdirc.util.validators.ValidationResponse;
26
+import com.dmdirc.util.validators.Validator;
25 27
 import com.dmdirc.config.IdentityManager;
26 28
 
27 29
 /**

+ 1
- 1
src/com/dmdirc/plugins/Plugin.java Ver arquivo

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.config.prefs.PreferencesManager;
26
-import com.dmdirc.config.prefs.validator.ValidationResponse;
26
+import com.dmdirc.util.validators.ValidationResponse;
27 27
 import java.io.File;
28 28
 
29 29
 /**

+ 1
- 1
src/com/dmdirc/plugins/PluginInfo.java Ver arquivo

@@ -27,7 +27,7 @@ import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.config.Identity;
28 28
 import com.dmdirc.config.IdentityManager;
29 29
 import com.dmdirc.config.InvalidIdentityFileException;
30
-import com.dmdirc.config.prefs.validator.ValidationResponse;
30
+import com.dmdirc.util.validators.ValidationResponse;
31 31
 import com.dmdirc.logger.ErrorLevel;
32 32
 import com.dmdirc.logger.Logger;
33 33
 import com.dmdirc.updater.Version;

+ 1
- 1
src/com/dmdirc/ui/input/InputHandler.java Ver arquivo

@@ -31,7 +31,7 @@ import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.commands.ValidatingCommand;
32 32
 import com.dmdirc.commandparser.commands.WrappableCommand;
33 33
 import com.dmdirc.commandparser.parsers.CommandParser;
34
-import com.dmdirc.config.prefs.validator.ValidationResponse;
34
+import com.dmdirc.util.validators.ValidationResponse;
35 35
 import com.dmdirc.interfaces.ConfigChangeListener;
36 36
 import com.dmdirc.plugins.PluginManager;
37 37
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;

test/com/dmdirc/config/prefs/validator/ActionGroupValidatorTest.java → test/com/dmdirc/actions/validators/ActionGroupValidatorTest.java Ver arquivo

@@ -20,8 +20,9 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.actions.validators;
24 24
 
25
+import com.dmdirc.actions.validators.ActionGroupValidator;
25 26
 import com.dmdirc.actions.ActionManager;
26 27
 import com.dmdirc.config.IdentityManager;
27 28
 import org.junit.BeforeClass;

test/com/dmdirc/config/prefs/validator/ConditionRuleValidatorTest.java → test/com/dmdirc/actions/validators/ConditionRuleValidatorTest.java Ver arquivo

@@ -20,8 +20,10 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.actions.validators;
24 24
 
25
+import com.dmdirc.actions.validators.ConditionRuleValidator;
26
+import com.dmdirc.util.validators.ValidationResponse;
25 27
 import org.junit.Test;
26 28
 import static org.junit.Assert.*;
27 29
 

+ 3
- 3
test/com/dmdirc/config/prefs/PreferencesSettingTest.java Ver arquivo

@@ -22,9 +22,9 @@
22 22
 package com.dmdirc.config.prefs;
23 23
 
24 24
 import com.dmdirc.config.IdentityManager;
25
-import com.dmdirc.config.prefs.validator.NotEmptyValidator;
26
-import com.dmdirc.config.prefs.validator.PermissiveValidator;
27
-import com.dmdirc.config.prefs.validator.StringLengthValidator;
25
+import com.dmdirc.util.validators.NotEmptyValidator;
26
+import com.dmdirc.util.validators.PermissiveValidator;
27
+import com.dmdirc.util.validators.StringLengthValidator;
28 28
 import java.util.HashMap;
29 29
 import java.util.Map;
30 30
 import org.junit.BeforeClass;

+ 0
- 38
test/com/dmdirc/config/prefs/validator/FileNameValidatorTest.java Ver arquivo

@@ -1,38 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class FileNameValidatorTest {
29
-
30
-    @Test
31
-    public void testValidate() {
32
-        final FileNameValidator rv = new FileNameValidator();
33
-        
34
-        assertTrue(rv.validate("/foo").isFailure());
35
-        assertFalse(rv.validate("filename").isFailure());
36
-    }
37
-
38
-}

+ 0
- 40
test/com/dmdirc/config/prefs/validator/IdentValidatorTest.java Ver arquivo

@@ -1,40 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class IdentValidatorTest {
29
-
30
-    @Test
31
-    public void testPass() {
32
-        assertTrue(new IdentValidator().validate("foo bar").isFailure());
33
-    }
34
-
35
-    @Test
36
-    public void testFail() {
37
-        assertFalse(new IdentValidator().validate("foo[]bar").isFailure());
38
-    }
39
-
40
-}

+ 0
- 40
test/com/dmdirc/config/prefs/validator/NicknameValidatorTest.java Ver arquivo

@@ -1,40 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class NicknameValidatorTest {
29
-
30
-    @Test
31
-    public void testPass() {
32
-        assertTrue(new NicknameValidator().validate("foo bar").isFailure());
33
-    }
34
-
35
-    @Test
36
-    public void testFail() {
37
-        assertFalse(new NicknameValidator().validate("foo[]bar").isFailure());
38
-    }
39
-
40
-}

+ 0
- 39
test/com/dmdirc/config/prefs/validator/NotEmptyValidatorTest.java Ver arquivo

@@ -1,39 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class NotEmptyValidatorTest {
28
-
29
-    @Test
30
-    public void testValidate() {
31
-        final NotEmptyValidator nev = new NotEmptyValidator();
32
-        
33
-        assertTrue(nev.validate("").isFailure());
34
-        assertTrue(nev.validate("").getFailureReason().indexOf("empty") > -1);
35
-        assertFalse(nev.validate("moo").isFailure());
36
-        assertFalse(nev.validate(" ").isFailure());
37
-    }
38
-
39
-}

+ 0
- 74
test/com/dmdirc/config/prefs/validator/NumericalValidatorTest.java Ver arquivo

@@ -1,74 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class NumericalValidatorTest {
28
-
29
-    @Test
30
-    public void testGetMax() {
31
-        assertEquals(10, new NumericalValidator(1, 10).getMax());
32
-        assertEquals(Integer.MAX_VALUE, new NumericalValidator(1, -1).getMax());
33
-    }
34
-
35
-    @Test
36
-    public void testGetMin() {
37
-        assertEquals(1, new NumericalValidator(1, 10).getMin());
38
-        assertEquals(Integer.MIN_VALUE, new NumericalValidator(-1, 10).getMin());
39
-    }
40
-
41
-    @Test
42
-    public void testNAN() {
43
-        final ValidationResponse vr = new NumericalValidator(3, 5).validate("foo");
44
-        
45
-        assertTrue(vr.isFailure());
46
-        assertTrue(vr.getFailureReason().indexOf("number") > -1);
47
-    }
48
-    
49
-    @Test
50
-    public void testMin() {
51
-        final NumericalValidator nv1 = new NumericalValidator(-1, -1);
52
-        final NumericalValidator nv2 = new NumericalValidator(-5, -1);
53
-        
54
-        assertFalse(nv1.validate("-5").isFailure());
55
-        assertFalse(nv2.validate("-5").isFailure());
56
-        assertFalse(nv2.validate("-4").isFailure());
57
-        assertFalse(nv2.validate("10").isFailure());
58
-        assertTrue(nv2.validate("-6").isFailure());
59
-    }
60
-    
61
-    @Test
62
-    public void testMax() {
63
-        final NumericalValidator nv1 = new NumericalValidator(-1, -1);
64
-        final NumericalValidator nv2 = new NumericalValidator(-1, 10);
65
-        
66
-        assertFalse(nv1.validate("-5").isFailure());
67
-        assertFalse(nv1.validate("50").isFailure());
68
-        assertFalse(nv2.validate("-5").isFailure());
69
-        assertFalse(nv2.validate("-4").isFailure());
70
-        assertFalse(nv2.validate("10").isFailure());
71
-        assertTrue(nv2.validate("11").isFailure());
72
-    }    
73
-
74
-}

+ 0
- 60
test/com/dmdirc/config/prefs/validator/OptionalValidatorTest.java Ver arquivo

@@ -1,60 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class OptionalValidatorTest {
29
-
30
-    @Test
31
-    public void testNoSeparator() {
32
-        final ValidationResponse res = new OptionalValidator(null).validate("foo");
33
-        assertTrue(res.isFailure());
34
-        assertTrue(res.getFailureReason().contains("boolean"));
35
-    }
36
-
37
-    @Test
38
-    public void testIllegalPrefix() {
39
-        final ValidationResponse res = new OptionalValidator(null).validate("foo:bar");
40
-        assertTrue(res.isFailure());
41
-        assertTrue(res.getFailureReason().contains("true"));
42
-        assertTrue(res.getFailureReason().contains("false"));
43
-    }
44
-
45
-    @Test
46
-    public void testTrueValidation() {
47
-        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(0, 3))
48
-                .validate("true:bar");
49
-        assertFalse(res.isFailure());
50
-    }
51
-
52
-    @Test
53
-    public void testFalseValidation() {
54
-        final ValidationResponse res = new OptionalValidator(new StringLengthValidator(0, 2))
55
-                .validate("true:bar");
56
-        assertTrue(res.isFailure());
57
-        assertTrue(res.getFailureReason().contains("at most 2"));
58
-    }
59
-
60
-}

+ 0
- 35
test/com/dmdirc/config/prefs/validator/PermissiveValidatorTest.java Ver arquivo

@@ -1,35 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class PermissiveValidatorTest {
28
-
29
-    @Test
30
-    public void testValidate() {
31
-        assertFalse(new PermissiveValidator<String>().validate("abc").isFailure());
32
-        assertFalse(new PermissiveValidator<String>().validate(null).isFailure());
33
-    }
34
-
35
-}

+ 0
- 37
test/com/dmdirc/config/prefs/validator/PortValidatorTest.java Ver arquivo

@@ -1,37 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class PortValidatorTest {
28
-
29
-    @Test
30
-    public void testBounds() {
31
-        final PortValidator pv = new PortValidator();
32
-        
33
-        assertEquals(1, pv.getMin());
34
-        assertEquals(65535, pv.getMax());
35
-    }
36
-
37
-}

+ 0
- 39
test/com/dmdirc/config/prefs/validator/RegexStringValidatorTest.java Ver arquivo

@@ -1,39 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class RegexStringValidatorTest {
28
-
29
-    @Test
30
-    public void testValidate() {
31
-        final String reason = "abc 123";
32
-        final RegexStringValidator rv = new RegexStringValidator("[0-9]{5}", reason);
33
-        
34
-        assertTrue(rv.validate("abc").isFailure());
35
-        assertEquals(reason, rv.validate("abc").getFailureReason());
36
-        assertFalse(rv.validate("55555").isFailure());
37
-    }
38
-
39
-}

+ 0
- 38
test/com/dmdirc/config/prefs/validator/RegexValidatorTest.java Ver arquivo

@@ -1,38 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class RegexValidatorTest {
29
-
30
-    @Test
31
-    public void testValidate() {
32
-        final RegexValidator rv = new RegexValidator();
33
-        
34
-        assertTrue(rv.validate("****").isFailure());
35
-        assertFalse(rv.validate("[a-z]").isFailure());
36
-    }
37
-
38
-}

+ 0
- 67
test/com/dmdirc/config/prefs/validator/StringLengthValidatorTest.java Ver arquivo

@@ -1,67 +0,0 @@
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.config.prefs.validator;
23
-
24
-import org.junit.Test;
25
-import static org.junit.Assert.*;
26
-
27
-public class StringLengthValidatorTest {
28
-
29
-    @Test
30
-    public void testUnlimited() {
31
-        final StringLengthValidator slv = new StringLengthValidator(-1, 10);
32
-        
33
-        assertFalse(slv.validate("123").isFailure());
34
-        assertFalse(slv.validate("").isFailure());
35
-        assertFalse(slv.validate("123456789").isFailure());
36
-        
37
-        final StringLengthValidator slv2 = new StringLengthValidator(0, -1);
38
-        
39
-        assertFalse(slv2.validate("123456789").isFailure());
40
-        assertFalse(slv2.validate("1").isFailure());
41
-    }
42
-    
43
-    @Test
44
-    public void testMinimum() {
45
-        final StringLengthValidator slv = new StringLengthValidator(5, 100);
46
-        
47
-        assertTrue(slv.validate("").isFailure());
48
-        assertTrue(slv.validate("123").isFailure());
49
-        assertTrue(slv.validate("1234").isFailure());
50
-        assertTrue(slv.validate("1234").getFailureReason().indexOf("at least 5") > -1);
51
-        assertFalse(slv.validate("12345").isFailure());
52
-        assertFalse(slv.validate("12345789").isFailure());
53
-    }
54
-    
55
-    @Test
56
-    public void testMaximum() {
57
-        final StringLengthValidator slv = new StringLengthValidator(0, 3);
58
-        
59
-        assertFalse(slv.validate("").isFailure());
60
-        assertFalse(slv.validate("12").isFailure());
61
-        assertFalse(slv.validate("123").isFailure());
62
-        assertTrue(slv.validate("1234").isFailure());
63
-        assertTrue(slv.validate("1234").getFailureReason().indexOf("at most 3") > -1);
64
-        assertTrue(slv.validate("12345").isFailure());
65
-    }    
66
-
67
-}

+ 0
- 41
test/com/dmdirc/config/prefs/validator/ValidatorChainTest.java Ver arquivo

@@ -1,41 +0,0 @@
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.config.prefs.validator;
24
-
25
-import org.junit.Test;
26
-import static org.junit.Assert.*;
27
-
28
-public class ValidatorChainTest {
29
-
30
-    @Test
31
-    public void testValidate() {
32
-        @SuppressWarnings("unchecked")
33
-        final ValidatorChain<String> chain = new ValidatorChain<String>(
34
-                new NotEmptyValidator(), new RegexStringValidator("[a-z]*", "abc"));
35
-        
36
-        assertTrue(chain.validate("").isFailure());
37
-        assertTrue(chain.validate("__").isFailure());
38
-        assertFalse(chain.validate("abc").isFailure());
39
-    }
40
-
41
-}

test/com/dmdirc/config/prefs/validator/URLProtocolValidatorTest.java → test/com/dmdirc/config/validators/URLProtocolValidatorTest.java Ver arquivo

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.config.prefs.validator;
23
+package com.dmdirc.config.validators;
24 24
 
25 25
 import com.dmdirc.config.IdentityManager;
26 26
 import com.dmdirc.config.InvalidIdentityFileException;

Carregando…
Cancelar
Salvar