View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.enforcer;
20  
21  import org.apache.maven.enforcer.rule.api.EnforcerRule;
22  import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
23  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
24  
25  /**
26   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
27   */
28  public class MockEnforcerRule implements EnforcerRule {
29  
30      private boolean failRule = false;
31  
32      private String cacheId = "";
33  
34      private boolean isCacheable = false;
35  
36      private boolean isResultValid = false;
37  
38      private boolean executed = false;
39  
40      public MockEnforcerRule(boolean fail) {
41          this.failRule = fail;
42      }
43  
44      public MockEnforcerRule(boolean fail, String cacheId, boolean isCacheable, boolean isResultValid) {
45          this.failRule = fail;
46          this.isCacheable = isCacheable;
47          this.isResultValid = isResultValid;
48          this.cacheId = cacheId;
49      }
50  
51      public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
52          executed = true;
53          if (isFailRule()) {
54              throw new EnforcerRuleException(" this condition is not allowed.");
55          }
56      }
57  
58      /**
59       * @return the failRule
60       */
61      public boolean isFailRule() {
62          return this.failRule;
63      }
64  
65      /**
66       * @param failRule the failRule to set
67       */
68      public void setFailRule(boolean failRule) {
69          this.failRule = failRule;
70      }
71  
72      /*
73       * (non-Javadoc)
74       * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId()
75       */
76      public String getCacheId() {
77          return cacheId;
78      }
79  
80      /*
81       * (non-Javadoc)
82       * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable()
83       */
84      public boolean isCacheable() {
85          return isCacheable;
86      }
87  
88      /*
89       * (non-Javadoc)
90       * @see
91       * org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule)
92       */
93      public boolean isResultValid(EnforcerRule theCachedRule) {
94          return isResultValid;
95      }
96  
97      /**
98       * Checks if the rule got executed.
99       *
100      * @return {@code true} if executed, {@code false} otherwise.
101      */
102     public boolean isExecuted() {
103         return executed;
104     }
105 }