View Javadoc
1   package org.apache.maven.plugins.jlink;
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 static org.assertj.core.api.Assertions.assertThat;
23  import static org.mockito.Mockito.mock;
24  import static org.mockito.Mockito.when;
25  
26  import java.io.File;
27  import java.util.Arrays;
28  import java.util.Collections;
29  
30  import org.apache.maven.plugin.logging.Log;
31  import org.junit.jupiter.api.BeforeEach;
32  import org.junit.jupiter.api.DisplayName;
33  import org.junit.jupiter.api.Test;
34  import org.mockito.Mockito;
35  
36  /**
37   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
38   */
39  public class AbstractJLinkMojoTest
40  {
41      private AbstractJLinkMojo mojoMock;
42  
43      @BeforeEach
44      public void before()
45      {
46          this.mojoMock = mock( AbstractJLinkMojo.class, Mockito.CALLS_REAL_METHODS );
47          when( mojoMock.getLog() ).thenReturn( mock( Log.class ) );
48      }
49  
50      @Test
51      @DisplayName( "convert should return single characters" )
52      public void convertShouldReturnSingleCharacter()
53      {
54          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x" );
55          assertThat( result ).isNotEmpty().hasToString( "x" );
56      }
57  
58      @Test
59      @DisplayName( "convert should two characters separated by path separator" )
60      public void convertShouldReturnTwoCharactersSeparatedByPathSeparator()
61      {
62          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x;a" );
63          assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
64      }
65  
66      @Test
67      @DisplayName( "convert using differential delimiter should return two characters separated by path separator" )
68      public void convertUsingDifferentDelimiterShouldReturnTwoCharactersSeparatedByPathSeparator()
69      {
70          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a" );
71          assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
72      }
73  
74      @Test
75      @DisplayName( "convertSeparatedModulePathToPlatformSeparatedModulePath() "
76                            + "should return two characters separated by path separator" )
77      public void convertUsingMultipleDelimitersShouldReturnTwoCharactersSeparatedByPathSeparator()
78      {
79          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a::" );
80          assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
81      }
82  
83      @Test
84      @DisplayName( "getPlatformDependSeparateList() should return a single character" )
85      public void getPlatformDependSeparateListShouldReturnASingleCharacter()
86      {
87          String result = mojoMock.getPlatformDependSeparateList( Collections.singletonList( "A" ) );
88          assertThat( result ).isEqualTo( "A" );
89      }
90  
91      @Test
92      @DisplayName( "getPlatformDependSeparateList() should return two characters separated" )
93      public void getPlatformDependSeparateListShouldReturnTwoCharactersSeparated()
94      {
95          String result = mojoMock.getPlatformDependSeparateList( Arrays.asList( "A", "B" ) );
96          assertThat( result ).isEqualTo( "A" + File.pathSeparatorChar + "B" );
97      }
98  
99      @Test
100     @DisplayName( "getPlatformDependSeparateList() should return three characters separated" )
101     public void getPlatformDependSeparateListShouldReturnThreeCharactersSeparated()
102     {
103         String result = mojoMock.getPlatformDependSeparateList( Arrays.asList( "A", "B", "C" ) );
104         assertThat( result ).isEqualTo( "A" + File.pathSeparatorChar + "B" + File.pathSeparatorChar + "C" );
105     }
106 
107     @Test
108     @DisplayName( "getCommaSeparatedList() should return a single character" )
109     public void getCommaSeparatedListShouldReturnASingleCharacter()
110     {
111         String result = mojoMock.getCommaSeparatedList( Collections.singletonList( "A" ) );
112         assertThat( result ).isEqualTo( "A" );
113     }
114 
115     @Test
116     @DisplayName( "getCommaSeparatedList() should return two characters separated by comma" )
117     public void getCommaSeparatedListShouldReturnTwoCharactersSeparatedByComma()
118     {
119         String result = mojoMock.getCommaSeparatedList( Arrays.asList( "A", "B" ) );
120         assertThat( result ).isEqualTo( "A,B" );
121     }
122 
123 }