View Javadoc
1   package org.apache.maven.plugins.enforcer.utils;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  import org.apache.maven.execution.MavenSession;
25  import org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator;
26  import org.apache.maven.plugins.enforcer.EnforcerTestUtils;
27  import org.apache.maven.plugins.enforcer.MockPathTranslator;
28  import org.apache.maven.plugins.enforcer.MockProject;
29  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
30  
31  /**
32   * The Class TestMockEnforcerExpressionEvaluator.
33   */
34  public class TestMockEnforcerExpressionEvaluator
35      extends TestCase
36  {
37  
38      /**
39       * Test evaluate.
40       */
41      public void testEvaluate()
42      {
43          MavenSession session = EnforcerTestUtils.getMavenSession();
44  
45          EnforcerExpressionEvaluator ev =
46              new MockEnforcerExpressionEvaluator( session, new MockPathTranslator(), new MockProject() );
47          assertMatch( ev, "SNAPSHOT" );
48          assertMatch( ev, "RELEASE" );
49          assertMatch( ev, "SNAPSHOT" );
50          assertMatch( ev, "LATEST" );
51          assertMatch( ev, "1.0" );
52      }
53  
54      /**
55       * Assert match.
56       *
57       * @param ev the ev
58       * @param exp the exp
59       */
60      public void assertMatch( EnforcerExpressionEvaluator ev, String exp )
61      {
62          // the mock enforcer should return the name of the expression as the value.
63          try
64          {
65              assertEquals( exp, ev.evaluate( "${" + exp + "}" ) );
66          }
67          catch ( ExpressionEvaluationException e )
68          {
69              fail( e.getLocalizedMessage() );
70          }
71      }
72  }