View Javadoc
1   package org.apache.maven.shared.model.fileset.mappers;
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.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertNull;
25  import static org.junit.Assert.fail;
26  
27  import org.apache.maven.shared.model.fileset.Mapper;
28  import org.junit.Test;
29  
30  /**
31   * A test-case for the MapperUtil.
32   */
33  public class MapperUtilTest
34  {
35      @Test
36      public void getFileNameMapperShouldReturnNull()
37          throws MapperException
38      {
39          assertNull( MapperUtil.getFileNameMapper( null ) );
40      }
41  
42      @Test
43      public void getFileNameMapperShouldReturnIdentityMapper()
44          throws MapperException
45      {
46          Mapper mapper = new Mapper();
47          FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
48          assertNotNull( fileNameMapper );
49          assertEquals( "/var/some-file.text", fileNameMapper.mapFileName( "/var/some-file.text" ) );
50      }
51  
52      @Test
53      public void getFileNameMapperShouldFileNameMapperType()
54          throws MapperException
55      {
56          // check with FileNameMapper type
57          Mapper mapper = new Mapper();
58          mapper.setType( "glob" );
59          mapper.setFrom( "*.java" );
60          mapper.setTo( "*.class" );
61          FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
62          assertNotNull( fileNameMapper );
63          assertEquals( "/var/SomeClasses.class", fileNameMapper.mapFileName( "/var/SomeClasses.java" ) );
64      }
65  
66      @Test
67      public void testGetFileNameMapper() throws MapperException
68      {
69          try
70          {
71              assertNull( MapperUtil.getFileNameMapper( null ) );
72          }
73          catch ( MapperException e )
74          {
75              fail( "Unexpected exception " + e );
76          }
77  
78          Mapper mapper = new Mapper();
79          try
80          {
81              // default to identity mapper.
82              FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
83              assertNotNull( fileNameMapper );
84              assertEquals( "/var/some-file.text", fileNameMapper.mapFileName( "/var/some-file.text" ) );
85          }
86          catch ( MapperException e )
87          {
88              fail( "Unexpected exception " + e );
89          }
90          // check with FileNameMapper type
91          mapper = new Mapper();
92          mapper.setType( "glob" );
93          mapper.setFrom( "*.java" );
94          mapper.setTo( "*.class" );
95  
96          FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
97          assertNotNull( fileNameMapper );
98          assertEquals( "/var/SomeClasses.class", fileNameMapper.mapFileName( "/var/SomeClasses.java" ) );
99      }
100 }