View Javadoc
1   package org.apache.maven.shared.filtering;
2   
3   import static org.hamcrest.MatcherAssert.assertThat;
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  
25  import java.util.LinkedHashSet;
26  
27  import org.hamcrest.Matchers;
28  import org.junit.Test;
29  
30  /**
31   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>.
32   */
33  public class AbstractMavenFilteringRequestTest
34  {
35      
36      private AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest();
37      private LinkedHashSet<String> delimiters = new LinkedHashSet<>();
38      
39      @Test
40      public void setDelimitersShouldNotChangeAnythingIfUsingNull()
41      {
42          request.setDelimiters( null, false );
43          assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@" ) );
44      }
45  
46      @Test
47      public void setDelimitersShouldNotChangeAnythingIfUsingEmpty()
48      {
49          request.setDelimiters( delimiters, false );
50          assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@" ) );
51      }
52  
53      @Test
54      public void setDelimitersShouldAddOnlyTheGivenDelimiter()
55      {
56          delimiters.add( "test" );
57          request.setDelimiters( delimiters, false );
58          assertThat( request.getDelimiters(), Matchers.contains( "test" ) );
59      }
60  
61      @Test
62      public void setDelimitersShouldAddDefaultDelimitersForNullElements()
63      {
64          delimiters.add( "test" );
65          delimiters.add( null );
66          delimiters.add( "second" );
67          request.setDelimiters( delimiters, false );
68          assertThat( request.getDelimiters(), Matchers.contains( "test", "${*}", "second" ) );
69      }
70  
71      @Test
72      public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNullGiven()
73      {
74          request.setDelimiters( null, true );
75          assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@" ) );
76      }
77  
78      @Test
79      public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNotNullGiven()
80      {
81          LinkedHashSet<String> delimiters = new LinkedHashSet<>();
82          request.setDelimiters( delimiters, true );
83          assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@" ) );
84      }
85  
86      @Test
87      public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingleElementIsGiven()
88      {
89          delimiters.add( "test" );
90          request.setDelimiters( delimiters, true );
91          assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@", "test" ) );
92      }
93  
94      @Test
95      public void setDelimitersShouldAddDefaultDelimitersForNullElement()
96      {
97          delimiters.add( "test" );
98          delimiters.add( null );
99          delimiters.add( "second" );
100         request.setDelimiters( delimiters, true );
101         assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@", "test", "second" ) );
102     }
103 
104 }