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.Before;
32  import org.junit.Test;
33  import org.mockito.Mockito;
34  
35  /**
36   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
37   */
38  public class AbsractJLinkMojoTest
39  {
40      private AbstractJLinkMojo mojoMock;
41  
42      @Before
43      public void before()
44      {
45          this.mojoMock = mock( AbstractJLinkMojo.class, Mockito.CALLS_REAL_METHODS );
46          when( mojoMock.getLog() ).thenReturn( mock( Log.class ) );
47      }
48  
49      @Test
50      public void convertShouldReturnSingleCharacter()
51      {
52          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x" );
53          assertThat( result.toString() ).isNotEmpty().isEqualTo( "x" );
54      }
55  
56      @Test
57      public void convertShouldReturnTwoCharactersSeparatedByPathSeparator()
58      {
59          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x;a" );
60          assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
61      }
62  
63      @Test
64      public void convertUsingDifferentDelimiterShouldReturnTwoCharactersSeparatedByPathSeparator()
65      {
66          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a" );
67          assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
68      }
69  
70      @Test
71      public void convertUsingMultipleDelimitersShouldReturnTwoCharactersSeparatedByPathSeparator()
72      {
73          StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a::" );
74          assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
75      }
76  
77      @Test
78      public void getPlatformDependSeparateListShouldReturnASingleCharacter()
79      {
80          String result = mojoMock.getPlatformDependSeparateList( Collections.singletonList( "A" ) );
81          assertThat( result ).isEqualTo( "A" );
82      }
83  
84      @Test
85      public void getPlatformDependSeparateListShouldReturnTwoCharactersSeparated()
86      {
87          String result = mojoMock.getPlatformDependSeparateList( Arrays.asList( "A", "B" ) );
88          assertThat( result ).isEqualTo( "A" + File.pathSeparatorChar + "B" );
89      }
90  
91      @Test
92      public void getPlatformDependSeparateListShouldReturnThreeCharactersSeparated()
93      {
94          String result = mojoMock.getPlatformDependSeparateList( Arrays.asList( "A", "B", "C" ) );
95          assertThat( result ).isEqualTo( "A" + File.pathSeparatorChar + "B" + File.pathSeparatorChar + "C" );
96      }
97  
98      @Test
99      public void getCommaSeparatedListShouldReturnASingleCharacter()
100     {
101         String result = mojoMock.getCommaSeparatedList( Arrays.asList( "A" ) );
102         assertThat( result ).isEqualTo( "A" );
103     }
104 
105     @Test
106     public void getCommaSeparatedListShouldReturnTwoCharactersSeparatedByComma()
107     {
108         String result = mojoMock.getCommaSeparatedList( Arrays.asList( "A", "B" ) );
109         assertThat( result ).isEqualTo( "A,B" );
110     }
111 
112 //    @Test
113 //    public void xxx()
114 //        throws MojoExecutionException, IOException, CommandLineException
115 //    {
116 //        Process p = mock( Process.class );
117 //
118 //        String b = "Error occured";
119 //        byte[] bytes = b.getBytes();
120 //        ByteArrayOutputStream baos = new ByteArrayOutputStream();
121 //        baos.write( bytes );
122 //        
123 //        when (p.getOutputStream()).thenReturn( baos );
124 //        
125 //        Commandline cmd = mock( Commandline.class );
126 //        when (cmd.execute()).thenReturn( p );
127 //        
128 //        File outputDirectory = mock( File.class );
129 //
130 //        mojoMock.executeCommand( cmd, outputDirectory );
131 //
132 //    }
133 }