Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1489#discussion_r59800993
  
    --- Diff: api/test/org/apache/cloudstack/acl/RuleTest.java ---
    @@ -0,0 +1,39 @@
    +package org.apache.cloudstack.acl;
    +
    +import com.cloud.exception.InvalidParameterValueException;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.Arrays;
    +
    +public class RuleTest {
    +
    +    @Test
    +    public void testToString() throws Exception {
    +        Rule rule = new Rule("someString");
    +        Assert.assertEquals(rule.toString(), "someString");
    +    }
    +
    +    @Test
    +    public void testValidateRuleWithValidData() throws Exception {
    +        for (String rule : Arrays.asList("a", "1", "someApi", 
"someApi321", "123SomeApi",
    +                "prefix*", "*middle*", "*Suffix",
    +                "*", "**", "f***", "m0nk3yMa**g1c*")) {
    +            Assert.assertTrue(Rule.validate(rule));
    +            Assert.assertEquals(new Rule(rule).toString(), rule);
    +        }
    +    }
    +
    +    @Test
    +    public void testValidateRuleWithInvalidData() throws Exception {
    +        for (String rule : Arrays.asList(null, "", " ", "  ", "\n", "\t", 
"\r", "\"", "\'",
    +                "^someApi$", "^someApi", "some$", "some-Api;", "some,Api",
    +                "^", "$", "^$", ".*", "\\w+", "r**l3rd0@Kr3", 
"j@s1n|+|0È·",
    +                "[a-z0-9-]+", 
"^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$")) {
    +            try {
    +                new Rule(rule);
    +                Assert.fail("Invalid rule, exception was expected");
    +            } catch (InvalidParameterValueException ignored) {}
    +        }
    --- End diff --
    
    This method can be simplified by removing the try-catch and added 
``expected=InvalidParameterValueException.class`` to the ``@Test`` annotation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to