View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.jlink;
20  
21  /*
22   * Licensed to the Apache Software Foundation (ASF) under one
23   * or more contributor license agreements.  See the NOTICE file
24   * distributed with this work for additional information
25   * regarding copyright ownership.  The ASF licenses this file
26   * to you under the Apache License, Version 2.0 (the
27   * "License"); you may not use this file except in compliance
28   * with the License.  You may obtain a copy of the License at
29   *
30   *   http://www.apache.org/licenses/LICENSE-2.0
31   *
32   * Unless required by applicable law or agreed to in writing,
33   * software distributed under the License is distributed on an
34   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
35   * KIND, either express or implied.  See the License for the
36   * specific language governing permissions and limitations
37   * under the License.
38   */
39  
40  import java.io.File;
41  import java.util.Arrays;
42  import java.util.Collections;
43  
44  import org.apache.maven.plugin.logging.Log;
45  import org.junit.jupiter.api.BeforeEach;
46  import org.junit.jupiter.api.DisplayName;
47  import org.junit.jupiter.api.Test;
48  import org.mockito.Mockito;
49  
50  import static org.assertj.core.api.Assertions.assertThat;
51  import static org.mockito.Mockito.mock;
52  import static org.mockito.Mockito.when;
53  
54  /**
55   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
56   */
57  public class AbstractJLinkMojoTest {
58      private AbstractJLinkMojo mojoMock;
59  
60      @BeforeEach
61      public void before() {
62          this.mojoMock = mock(AbstractJLinkMojo.class, Mockito.CALLS_REAL_METHODS);
63          when(mojoMock.getLog()).thenReturn(mock(Log.class));
64      }
65  
66      @Test
67      @DisplayName("convert should return single characters")
68      public void convertShouldReturnSingleCharacter() {
69          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath("x");
70          assertThat(result).isNotEmpty().hasToString("x");
71      }
72  
73      @Test
74      @DisplayName("convert should two characters separated by path separator")
75      public void convertShouldReturnTwoCharactersSeparatedByPathSeparator() {
76          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath("x;a");
77          assertThat(result).hasToString("x" + File.pathSeparatorChar + "a");
78      }
79  
80      @Test
81      @DisplayName("convert using differential delimiter should return two characters separated by path separator")
82      public void convertUsingDifferentDelimiterShouldReturnTwoCharactersSeparatedByPathSeparator() {
83          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath("x:a");
84          assertThat(result).hasToString("x" + File.pathSeparatorChar + "a");
85      }
86  
87      @Test
88      @DisplayName("convertSeparatedModulePathToPlatformSeparatedModulePath() "
89              + "should return two characters separated by path separator")
90      public void convertUsingMultipleDelimitersShouldReturnTwoCharactersSeparatedByPathSeparator() {
91          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath("x:a::");
92          assertThat(result).hasToString("x" + File.pathSeparatorChar + "a");
93      }
94  
95      @Test
96      @DisplayName("getPlatformDependSeparateList() should return a single character")
97      public void getPlatformDependSeparateListShouldReturnASingleCharacter() {
98          String result = mojoMock.getPlatformDependSeparateList(Collections.singletonList("A"));
99          assertThat(result).isEqualTo("A");
100     }
101 
102     @Test
103     @DisplayName("getPlatformDependSeparateList() should return two characters separated")
104     public void getPlatformDependSeparateListShouldReturnTwoCharactersSeparated() {
105         String result = mojoMock.getPlatformDependSeparateList(Arrays.asList("A", "B"));
106         assertThat(result).isEqualTo("A" + File.pathSeparatorChar + "B");
107     }
108 
109     @Test
110     @DisplayName("getPlatformDependSeparateList() should return three characters separated")
111     public void getPlatformDependSeparateListShouldReturnThreeCharactersSeparated() {
112         String result = mojoMock.getPlatformDependSeparateList(Arrays.asList("A", "B", "C"));
113         assertThat(result).isEqualTo("A" + File.pathSeparatorChar + "B" + File.pathSeparatorChar + "C");
114     }
115 
116     @Test
117     @DisplayName("getCommaSeparatedList() should return a single character")
118     public void getCommaSeparatedListShouldReturnASingleCharacter() {
119         String result = mojoMock.getCommaSeparatedList(Collections.singletonList("A"));
120         assertThat(result).isEqualTo("A");
121     }
122 
123     @Test
124     @DisplayName("getCommaSeparatedList() should return two characters separated by comma")
125     public void getCommaSeparatedListShouldReturnTwoCharactersSeparatedByComma() {
126         String result = mojoMock.getCommaSeparatedList(Arrays.asList("A", "B"));
127         assertThat(result).isEqualTo("A,B");
128     }
129 }