View Javadoc
1   package org.apache.maven.model.profile.activation;
2   
3   import java.util.Objects;
4   
5   /*
6    * Licensed to the Apache Software Foundation (ASF) under one
7    * or more contributor license agreements.  See the NOTICE file
8    * distributed with this work for additional information
9    * regarding copyright ownership.  The ASF licenses this file
10   * to you under the Apache License, Version 2.0 (the
11   * "License"); you may not use this file except in compliance
12   * with the License.  You may obtain a copy of the License at
13   *
14   *   http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing,
17   * software distributed under the License is distributed on an
18   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19   * KIND, either express or implied.  See the License for the
20   * specific language governing permissions and limitations
21   * under the License.
22   */
23  
24  import java.util.Properties;
25  
26  import org.apache.maven.model.Profile;
27  import org.apache.maven.model.building.SimpleProblemCollector;
28  import org.apache.maven.model.profile.DefaultProfileActivationContext;
29  import org.apache.maven.model.profile.ProfileActivationContext;
30  
31  import junit.framework.TestCase;
32  
33  /**
34   * Provides common services to test {@link ProfileActivator} implementations.
35   *
36   * @author Benjamin Bentmann
37   */
38  public abstract class AbstractProfileActivatorTest<T extends ProfileActivator>
39      extends TestCase
40  {
41  
42      private Class<T> activatorClass;
43  
44      protected T activator;
45  
46      public AbstractProfileActivatorTest( Class<T> activatorClass )
47      {
48          this.activatorClass = Objects.requireNonNull( activatorClass, "activatorClass cannot be null" );;
49      }
50  
51      @Override
52      protected void setUp()
53          throws Exception
54      {
55          super.setUp();
56  
57          activator = activatorClass.getConstructor().newInstance();
58      }
59  
60      @Override
61      protected void tearDown()
62          throws Exception
63      {
64          activator = null;
65  
66          super.tearDown();
67      }
68  
69      protected ProfileActivationContext newContext( final Properties userProperties, final Properties systemProperties )
70      {
71          DefaultProfileActivationContext context = new DefaultProfileActivationContext();
72          return context.setUserProperties( userProperties ).setSystemProperties( systemProperties );
73      }
74  
75      protected void assertActivation( boolean active, Profile profile, ProfileActivationContext context )
76      {
77          SimpleProblemCollector problems = new SimpleProblemCollector();
78  
79          assertEquals( active, activator.isActive( profile, context, problems ) );
80  
81          assertEquals( problems.getErrors().toString(), 0, problems.getErrors().size() );
82          assertEquals( problems.getWarnings().toString(), 0, problems.getWarnings().size() );
83      }
84  
85  }