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  // TODO: Auto-generated Javadoc
32  /**
33   * The Class TestMockEnforcerExpressionEvaluator.
34   */
35  public class TestMockEnforcerExpressionEvaluator
36      extends TestCase
37  {
38  
39      /**
40       * Test evaluate.
41       */
42      public void testEvaluate()
43      {
44          MavenSession session = EnforcerTestUtils.getMavenSession();
45  
46          EnforcerExpressionEvaluator ev =
47              new MockEnforcerExpressionEvaluator( session, new MockPathTranslator(), new MockProject() );
48          assertMatch( ev, "SNAPSHOT" );
49          assertMatch( ev, "RELEASE" );
50          assertMatch( ev, "SNAPSHOT" );
51          assertMatch( ev, "LATEST" );
52          assertMatch( ev, "1.0" );
53      }
54  
55      /**
56       * Assert match.
57       *
58       * @param ev the ev
59       * @param exp the exp
60       */
61      public void assertMatch( EnforcerExpressionEvaluator ev, String exp )
62      {
63          // the mock enforcer should return the name of the expression as the value.
64          try
65          {
66              assertEquals( exp, ev.evaluate( "${" + exp + "}" ) );
67          }
68          catch ( ExpressionEvaluationException e )
69          {
70              fail( e.getLocalizedMessage() );
71          }
72      }
73  }