Author: khmarbaise
Date: Thu Sep  4 19:45:50 2014
New Revision: 1622539

URL: http://svn.apache.org/r1622539
Log:
- Refactored code to extract LineEndings functionality and going more 
  into Java 5 direction with an enum type instead of hard coded string
  values.

Added:
    
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndings.java
    
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtilsTest.java
      - copied, changed from r1622302, 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
Removed:
    
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
Modified:
    maven/plugins/trunk/maven-assembly-plugin/pom.xml
    
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
    
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
    
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java

Modified: maven/plugins/trunk/maven-assembly-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/pom.xml?rev=1622539&r1=1622538&r2=1622539&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-assembly-plugin/pom.xml Thu Sep  4 19:45:50 2014
@@ -19,9 +19,12 @@ specific language governing permissions 
 under the License.
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+<project
+  xmlns="http://maven.apache.org/POM/4.0.0";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
   <modelVersion>4.0.0</modelVersion>
-  
+
   <parent>
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
@@ -190,6 +193,12 @@ under the License.
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>2.5.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>jdom</groupId>
       <artifactId>jdom</artifactId>
       <version>1.0</version>
@@ -230,7 +239,7 @@ under the License.
         
<directory>${project.build.directory}/generated-resources/plexus</directory>
       </resource>
     </resources>
-    
+
     <plugins>
       <plugin>
         <groupId>org.codehaus.plexus</groupId>
@@ -370,7 +379,7 @@ under the License.
             <configuration>
               <localRepositoryPath>${localRepositoryPath}</localRepositoryPath>
               <properties>
-                <useJvmChmod>${useJvmChmod}</useJvmChmod> 
+                <useJvmChmod>${useJvmChmod}</useJvmChmod>
                 <testVersion>${testVersion}</testVersion>
                 
<localRepositoryPath>${localRepositoryPath}</localRepositoryPath>
                 
<invokerPluginVersion>${invokerPluginVersion}</invokerPluginVersion>
@@ -410,7 +419,7 @@ under the License.
                     <useJvmChmod>${useJvmChmod}</useJvmChmod>
                   </properties>
                   <debug>${it.debug}</debug>
-                  <settingsFile>src/it/settings.xml</settingsFile> 
+                  <settingsFile>src/it/settings.xml</settingsFile>
                   <pomIncludes>
                     <pomInclude>${it.pomIncludes}</pomInclude>
                   </pomIncludes>
@@ -423,7 +432,7 @@ under the License.
 
                     
<pomExclude>dependency-sets/depSet-enum-vs-wildcard/enum/pom.xml</pomExclude>
                     
<pomExclude>dependency-sets/depSet-enum-vs-wildcard/wildcard/pom.xml</pomExclude>
-                    
+
                     <pomExclude>**/child*/pom.xml</pomExclude>
                     <pomExclude>**/module*/pom.xml</pomExclude>
                     <pomExclude>**/descriptor/pom.xml</pomExclude>
@@ -434,7 +443,7 @@ under the License.
                   <postBuildHookScript>verify</postBuildHookScript>
                 </configuration>
               </execution>
-           </executions>
+            </executions>
           </plugin>
         </plugins>
       </build>

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java?rev=1622539&r1=1622538&r2=1622539&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
 Thu Sep  4 19:45:50 2014
@@ -30,6 +30,7 @@ import javax.annotation.Nullable;
 
 import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.plugin.assembly.utils.LineEndings;
 import org.apache.maven.plugin.assembly.utils.LineEndingsUtils;
 import org.apache.maven.shared.filtering.MavenFileFilterRequest;
 import org.apache.maven.shared.filtering.MavenFilteringException;
@@ -61,7 +62,7 @@ public class FileFormatter
         return format( source, filter, lineEnding, 
configSource.getTemporaryRootDirectory(), encoding );
     }
 
-    public File format( @Nonnull File source, boolean filter, String 
lineEnding, @Nullable File tempRoot,
+    public File format( @Nonnull File source, boolean filter, String 
lineEndingCharacters, @Nullable File tempRoot,
                         String encoding )
         throws AssemblyFormattingException
     {
@@ -72,7 +73,7 @@ public class FileFormatter
         if ( StringUtils.isEmpty( encoding ) && filter )
         {
             logger.warn( "File encoding has not been set, using platform 
encoding " + ReaderFactory.FILE_ENCODING
-                             + ", i.e. build is platform dependent!" );
+                + ", i.e. build is platform dependent!" );
         }
 
         if ( filter )
@@ -80,10 +81,10 @@ public class FileFormatter
             result = doFileFilter( source, tempRoot, encoding, 
configSource.getEscapeString() );
         }
 
-        String lineEndingChars = LineEndingsUtils.getLineEndingCharacters( 
lineEnding );
-        if ( lineEndingChars != null )
+        LineEndings lineEnding = LineEndingsUtils.getLineEnding( 
lineEndingCharacters );
+        if ( !LineEndings.keep.equals( lineEnding ) )
         {
-            result = formatLineEndings( lineEndingChars, result, tempRoot, 
encoding );
+            result = formatLineEndings( lineEnding, result, tempRoot, encoding 
);
         }
 
         return result;
@@ -96,7 +97,7 @@ public class FileFormatter
         {
             File target = FileUtils.createTempFile( source.getName() + ".", 
".filtered", tempRoot );
 
-            //@todo this test can be improved
+            // @todo this test can be improved
             boolean isPropertiesFile = source.getName().toLowerCase( 
Locale.ENGLISH ).endsWith( ".properties" );
 
             MavenFileFilterRequest filterRequest =
@@ -114,7 +115,7 @@ public class FileFormatter
         }
     }
 
-    private File formatLineEndings( String lineEndingChars, File source, File 
tempRoot, String encoding )
+    private File formatLineEndings( LineEndings lineEnding, File source, File 
tempRoot, String encoding )
         throws AssemblyFormattingException
     {
         Reader contentReader = null;
@@ -122,7 +123,7 @@ public class FileFormatter
         {
             File target = FileUtils.createTempFile( source.getName() + ".", 
".formatted", tempRoot );
 
-            LineEndingsUtils.convertLineEndings( source, target, 
lineEndingChars, null, encoding );
+            LineEndingsUtils.convertLineEndings( source, target, lineEnding, 
null, encoding );
 
             return target;
         }
@@ -132,8 +133,7 @@ public class FileFormatter
         }
         catch ( IOException e )
         {
-            throw new AssemblyFormattingException( "Error line formatting file 
'" + source + "': " + e.getMessage(),
-                                                   e );
+            throw new AssemblyFormattingException( "Error line formatting file 
'" + source + "': " + e.getMessage(), e );
         }
         finally
         {

Added: 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndings.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndings.java?rev=1622539&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndings.java
 (added)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndings.java
 Thu Sep  4 19:45:50 2014
@@ -0,0 +1,49 @@
+package org.apache.maven.plugin.assembly.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Enumeration to keep the different line
+ * ending types we support.
+ * 
+ * @author Karl-Heinz Marbaise <a 
href="mailto:[email protected]";>[email protected]</a>
+ *
+ */
+public enum LineEndings
+{
+    keep( null ), 
+    dos( "\r\n" ), 
+    windows( "\r\n" ), 
+    unix( "\n" ), 
+    crlf( "\r\n" ), 
+    lf( "\n" );
+
+    private String lineEndingCharacters;
+
+    private LineEndings( String lineEndingCharacters )
+    {
+        this.lineEndingCharacters = lineEndingCharacters;
+    }
+
+    public String getLineEndingCharacters()
+    {
+        return this.lineEndingCharacters;
+    }
+}
\ No newline at end of file

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java?rev=1622539&r1=1622538&r2=1622539&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
 Thu Sep  4 19:45:50 2014
@@ -36,25 +36,11 @@ import org.apache.maven.plugin.assembly.
 import org.codehaus.plexus.util.IOUtil;
 
 /**
- * Line Ending class which contains
- * convenience methods to change line endings. 
- *
+ * Line Ending class which contains convenience methods to change line endings.
  */
 public final class LineEndingsUtils
 {
 
-    public static final String LINE_ENDING_KEEP = "keep";
-
-    public static final String LINE_ENDING_DOS = "dos";
-
-    public static final String LINE_ENDING_WINDOWS = "windows";
-
-    public static final String LINE_ENDING_UNIX = "unix";
-
-    public static final String LINE_ENDING_CRLF = "crlf";
-
-    public static final String LINE_ENDING_LF = "lf";
-
     private LineEndingsUtils()
     {
         // prevent creations of instances.
@@ -73,7 +59,7 @@ public final class LineEndingsUtils
      *            based on the input file
      * @param encoding The encoding to use, null for platform encoding
      */
-    public static void convertLineEndings( @Nonnull File source, @Nonnull File 
dest, String lineEndings,
+    public static void convertLineEndings( @Nonnull File source, @Nonnull File 
dest, LineEndings lineEndings,
                                            Boolean atEndOfFile, String 
encoding )
         throws IOException
     {
@@ -94,7 +80,7 @@ public final class LineEndingsUtils
                     byte last = raf.readByte();
                     if ( last == '\n' )
                     {
-                        eofChars = lineEndings;
+                        eofChars = lineEndings.getLineEndingCharacters();
                     }
                 }
             }
@@ -115,7 +101,7 @@ public final class LineEndingsUtils
         }
         else if ( atEndOfFile == true )
         {
-            eofChars = lineEndings;
+            eofChars = lineEndings.getLineEndingCharacters();
         }
 
         BufferedReader in = null;
@@ -144,7 +130,7 @@ public final class LineEndingsUtils
                 line = in.readLine();
                 if ( line != null )
                 {
-                    out.write( lineEndings );
+                    out.write( lineEndings.getLineEndingCharacters() );
                 }
                 else
                 {
@@ -161,29 +147,41 @@ public final class LineEndingsUtils
         }
     }
 
-    @Nullable
-    public static String getLineEndingCharacters( @Nullable String lineEnding )
+    public static LineEndings getLineEnding( @Nullable String lineEnding )
         throws AssemblyFormattingException
     {
-        String value = lineEnding;
+        LineEndings result = LineEndings.keep;
         if ( lineEnding != null )
         {
-            if ( LINE_ENDING_KEEP.equals( lineEnding ) )
+            try
             {
-                value = null;
+                result = LineEndings.valueOf( lineEnding );
             }
-            else if ( LINE_ENDING_DOS.equals( lineEnding ) || 
LINE_ENDING_WINDOWS.equals( lineEnding )
-                || LINE_ENDING_CRLF.equals( lineEnding ) )
+            catch ( IllegalArgumentException e )
             {
-                value = "\r\n";
+                throw new AssemblyFormattingException( "Illegal lineEnding 
specified: '" + lineEnding + "'", e );
             }
-            else if ( LINE_ENDING_UNIX.equals( lineEnding ) || 
LINE_ENDING_LF.equals( lineEnding ) )
+        }
+        return result;
+    }
+
+    @Nullable
+    public static String getLineEndingCharacters( @Nullable String lineEnding )
+        throws AssemblyFormattingException
+    {
+
+        String value = lineEnding;
+
+        if ( lineEnding != null )
+        {
+
+            try
             {
-                value = "\n";
+                value = LineEndings.valueOf( lineEnding 
).getLineEndingCharacters();
             }
-            else
+            catch ( IllegalArgumentException e )
             {
-                throw new AssemblyFormattingException( "Illegal lineEnding 
specified: '" + lineEnding + "'" );
+                throw new AssemblyFormattingException( "Illegal lineEnding 
specified: '" + lineEnding + "'", e );
             }
         }
 

Modified: 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java?rev=1622539&r1=1622538&r2=1622539&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
 Thu Sep  4 19:45:50 2014
@@ -29,7 +29,7 @@ import org.apache.maven.plugin.assembly.
 import org.apache.maven.plugin.assembly.model.FileSet;
 import org.apache.maven.plugin.assembly.testutils.MockManager;
 import org.apache.maven.plugin.assembly.testutils.TestFileManager;
-import org.apache.maven.plugin.assembly.utils.LineEndingsUtils;
+import org.apache.maven.plugin.assembly.utils.LineEndings;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.logging.Logger;
@@ -52,7 +52,8 @@ public class FileSetFormatterTest
     private MockControl configSourceControl;
 
     @Override
-    public void setUp() throws Exception
+    public void setUp()
+        throws Exception
     {
         super.setUp();
 
@@ -69,7 +70,8 @@ public class FileSetFormatterTest
     }
 
     @Override
-    public void tearDown() throws IOException
+    public void tearDown()
+        throws IOException
     {
         fileManager.cleanUp();
     }
@@ -92,7 +94,7 @@ public class FileSetFormatterTest
         throws AssemblyFormattingException, IOException
     {
         final FileSet fs = new FileSet();
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_KEEP );
+        fs.setLineEnding( LineEndings.keep.name() );
 
         final FileSetFormatter formatter = new FileSetFormatter( configSource, 
logger );
 
@@ -110,7 +112,7 @@ public class FileSetFormatterTest
 
         final FileSet fs = new FileSet();
 
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_LF );
+        fs.setLineEnding( LineEndings.lf.name() );
         fs.setDirectory( dir.getCanonicalPath() );
         fs.addExclude( "**/*" );
 
@@ -121,7 +123,8 @@ public class FileSetFormatterTest
         assertEquals( dir, result );
     }
 
-    public void testShouldConvertLineEndingsOnTwoFiles() throws 
AssemblyFormattingException, IOException
+    public void testShouldConvertLineEndingsOnTwoFiles()
+        throws AssemblyFormattingException, IOException
     {
         final File dir = fileManager.createTempDir();
 
@@ -133,7 +136,7 @@ public class FileSetFormatterTest
 
         final FileSet fs = new FileSet();
 
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
+        fs.setLineEnding( LineEndings.crlf.name() );
         fs.setDirectory( dir.getCanonicalPath() );
         fs.addInclude( "**/*.txt" );
 
@@ -146,7 +149,7 @@ public class FileSetFormatterTest
         configSourceControl.setReturnValue( "UTF-8", MockControl.ONE_OR_MORE );
 
         mockManager.replayAll();
-        
+
         final File result = formatter.formatFileSetForAssembly( dir, fs );
 
         assertFalse( dir.equals( result ) );
@@ -175,7 +178,7 @@ public class FileSetFormatterTest
 
         final FileSet fs = new FileSet();
 
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
+        fs.setLineEnding( LineEndings.crlf.name() );
         fs.setDirectory( dir.getCanonicalPath() );
         fs.addExclude( "**/two.txt" );
 
@@ -188,7 +191,7 @@ public class FileSetFormatterTest
         configSourceControl.setReturnValue( "UTF-8", MockControl.ONE_OR_MORE );
 
         mockManager.replayAll();
-        
+
         final File result = formatter.formatFileSetForAssembly( dir, fs );
 
         assertFalse( dir.equals( result ) );
@@ -217,7 +220,7 @@ public class FileSetFormatterTest
 
         final FileSet fs = new FileSet();
 
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
+        fs.setLineEnding( LineEndings.crlf.name() );
         fs.setDirectory( dir.getCanonicalPath() );
         fs.addInclude( "**/one.txt" );
 
@@ -230,7 +233,7 @@ public class FileSetFormatterTest
         configSourceControl.setReturnValue( "UTF-8", MockControl.ONE_OR_MORE );
 
         mockManager.replayAll();
-        
+
         final File result = formatter.formatFileSetForAssembly( dir, fs );
 
         assertFalse( dir.equals( result ) );
@@ -258,7 +261,7 @@ public class FileSetFormatterTest
 
         final FileSet fs = new FileSet();
 
-        fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
+        fs.setLineEnding( LineEndings.crlf.name() );
         fs.setDirectory( dir.getCanonicalPath() );
 
         final FileSetFormatter formatter = new FileSetFormatter( configSource, 
logger );
@@ -270,7 +273,7 @@ public class FileSetFormatterTest
         configSourceControl.setReturnValue( "UTF-8", MockControl.ONE_OR_MORE );
 
         mockManager.replayAll();
-        
+
         final File result = formatter.formatFileSetForAssembly( dir, fs );
 
         assertFalse( dir.equals( result ) );
@@ -286,7 +289,8 @@ public class FileSetFormatterTest
         }
     }
 
-    public void testShouldFilterSeveralFiles() throws Exception
+    public void testShouldFilterSeveralFiles()
+        throws Exception
     {
         final File basedir = fileManager.createTempDir();
 
@@ -338,8 +342,7 @@ public class FileSetFormatterTest
         model.setVersion( "version" );
 
         final MavenProject project = new MavenProject( model );
-        project.getBuild()
-               .setFilters( filterFilenames );
+        project.getBuild().setFilters( filterFilenames );
 
         configSource.getProject();
         configSourceControl.setReturnValue( project, MockControl.ONE_OR_MORE );

Copied: 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtilsTest.java
 (from r1622302, 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java)
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtilsTest.java?p2=maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtilsTest.java&p1=maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java&r1=1622302&r2=1622539&rev=1622539&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
 (original)
+++ 
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtilsTest.java
 Thu Sep  4 19:45:50 2014
@@ -19,6 +19,9 @@ package org.apache.maven.plugin.assembly
  * under the License.
  */
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
@@ -26,23 +29,46 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
 
-import junit.framework.TestCase;
-
-import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
 import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
-import org.apache.maven.plugin.assembly.testutils.MockManager;
-import org.apache.maven.plugin.assembly.testutils.TestFileManager;
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.archiver.UnArchiver;
-import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 import org.codehaus.plexus.util.IOUtil;
-import org.easymock.MockControl;
+import org.junit.Test;
 
-public class LineEndingUtilsTest
-    extends TestCase
+public class LineEndingsUtilsTest
 {
 
+    public static final String CRLF = "\r\n";
+
+    public static final String LF = "\n";
+
+    @Test
+    public void shouldWorkCauseWeTestJdkEnumConversion()
+    {
+        LineEndings lineEnding = LineEndings.valueOf( "windows" );
+        assertEquals( CRLF, lineEnding.getLineEndingCharacters() );
+    }
+
+    @Test
+    public void shouldReturnDosLineEnding()
+    {
+        assertEquals( CRLF, LineEndings.windows.getLineEndingCharacters() );
+        assertEquals( CRLF, LineEndings.dos.getLineEndingCharacters() );
+        assertEquals( CRLF, LineEndings.crlf.getLineEndingCharacters() );
+    }
+
+    @Test
+    public void shouldReturnUnixLineEnding()
+    {
+        assertEquals( LF, LineEndings.unix.getLineEndingCharacters() );
+        assertEquals( LF, LineEndings.lf.getLineEndingCharacters() );
+    }
+
+    @Test
+    public void shouldReturnNullAsLineEndingForKeep()
+    {
+        assertEquals( null, LineEndings.keep.getLineEndingCharacters() );
+    }
+
+    @Test
     public void testGetLineEndingChars_ShouldReturnDosLineEnding()
         throws AssemblyFormattingException
     {
@@ -51,6 +77,7 @@ public class LineEndingUtilsTest
         assertEquals( "\r\n", LineEndingsUtils.getLineEndingCharacters( "crlf" 
) );
     }
 
+    @Test
     public void testGetLineEndingChars_ShouldReturnUnixLineEnding()
         throws AssemblyFormattingException
     {
@@ -58,177 +85,188 @@ public class LineEndingUtilsTest
         assertEquals( "\n", LineEndingsUtils.getLineEndingCharacters( "lf" ) );
     }
 
+    @Test
     public void testGetLineEndingChars_ShouldReturnNullLineEnding()
         throws AssemblyFormattingException
     {
         assertNull( LineEndingsUtils.getLineEndingCharacters( "keep" ) );
     }
 
+    @Test( expected = AssemblyFormattingException.class )
     public void 
testGetLineEndingChars_ShouldThrowFormattingExceptionWithInvalidHint()
+        throws AssemblyFormattingException
     {
-        try
-        {
-            LineEndingsUtils.getLineEndingCharacters( "invalid" );
-
-            fail( "Invalid line-ending hint should throw a formatting 
exception." );
-        }
-        catch ( AssemblyFormattingException e )
-        {
-        }
+        LineEndingsUtils.getLineEndingCharacters( "invalid" );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceLFWithCRLF()
         throws IOException
     {
         String test = "This is a \ntest.";
         String check = "This is a \r\ntest.";
 
-        testConversion( test, check, "\r\n", null );
+        testConversion( test, check, LineEndings.crlf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceLFWithCRLFAtEOF()
         throws IOException
     {
         String test = "This is a \ntest.\n";
         String check = "This is a \r\ntest.\r\n";
 
-        testConversion( test, check, "\r\n", null );
+        testConversion( test, check, LineEndings.crlf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceCRLFWithLF()
         throws IOException
     {
         String test = "This is a \r\ntest.";
         String check = "This is a \ntest.";
 
-        testConversion( test, check, "\n", null );
+        testConversion( test, check, LineEndings.lf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceCRLFWithLFAtEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.\r\n";
         String check = "This is a \ntest.\n";
 
-        testConversion( test, check, "\n", null );
+        testConversion( test, check, LineEndings.lf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceLFWithLF()
         throws IOException
     {
         String test = "This is a \ntest.";
         String check = "This is a \ntest.";
 
-        testConversion( test, check, "\n", null );
+        testConversion( test, check, LineEndings.lf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceLFWithLFAtEOF()
         throws IOException
     {
         String test = "This is a \ntest.\n";
         String check = "This is a \ntest.\n";
 
-        testConversion( test, check, "\n", null );
+        testConversion( test, check, LineEndings.lf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceCRLFWithCRLF()
         throws IOException
     {
         String test = "This is a \r\ntest.";
         String check = "This is a \r\ntest.";
 
-        testConversion( test, check, "\r\n", null );
+        testConversion( test, check, LineEndings.crlf, null );
     }
 
+    @Test
     public void testConvertLineEndings_ShouldReplaceCRLFWithCRLFAtEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.\r\n";
         String check = "This is a \r\ntest.\r\n";
 
-        testConversion( test, check, "\r\n", null );
+        testConversion( test, check, LineEndings.crlf, null );
     }
 
+    @Test
     public void testConvertLineEndings_LFToCRLFNoEOFForceEOF()
         throws IOException
     {
         String test = "This is a \ntest.";
         String check = "This is a \r\ntest.\r\n";
 
-        testConversion( test, check, "\r\n", true );
+        testConversion( test, check, LineEndings.crlf, true );
     }
 
+    @Test
     public void testConvertLineEndings_LFToCRLFWithEOFForceEOF()
         throws IOException
     {
         String test = "This is a \ntest.\n";
         String check = "This is a \r\ntest.\r\n";
 
-        testConversion( test, check, "\r\n", true );
+        testConversion( test, check, LineEndings.crlf, true );
     }
 
+    @Test
     public void testConvertLineEndings_LFToCRLFNoEOFStripEOF()
         throws IOException
     {
         String test = "This is a \ntest.";
         String check = "This is a \r\ntest.";
 
-        testConversion( test, check, "\r\n", false );
+        testConversion( test, check, LineEndings.crlf, false );
     }
 
+    @Test
     public void testConvertLineEndings_LFToCRLFWithEOFStripEOF()
         throws IOException
     {
         String test = "This is a \ntest.\n";
         String check = "This is a \r\ntest.";
 
-        testConversion( test, check, "\r\n", false );
+        testConversion( test, check, LineEndings.crlf, false );
     }
 
+    @Test
     public void testConvertLineEndings_CRLFToLFNoEOFForceEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.";
         String check = "This is a \ntest.\n";
 
-        testConversion( test, check, "\n", true );
+        testConversion( test, check, LineEndings.lf, true );
     }
 
+    @Test
     public void testConvertLineEndings_CRLFToLFWithEOFForceEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.\r\n";
         String check = "This is a \ntest.\n";
 
-        testConversion( test, check, "\n", true );
+        testConversion( test, check, LineEndings.lf, true );
     }
 
+    @Test
     public void testConvertLineEndings_CRLFToLFNoEOFStripEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.";
         String check = "This is a \ntest.";
 
-        testConversion( test, check, "\n", false );
+        testConversion( test, check, LineEndings.lf, false );
     }
 
+    @Test
     public void testConvertLineEndings_CRLFToLFWithEOFStripEOF()
         throws IOException
     {
         String test = "This is a \r\ntest.\r\n";
         String check = "This is a \ntest.";
 
-        testConversion( test, check, "\n", false );
+        testConversion( test, check, LineEndings.lf, false );
     }
 
-    private void testConversion( String test, String check, String 
lineEndingChars, Boolean eof )
+    private void testConversion( String test, String check, LineEndings 
lineEndingChars, Boolean eof )
         throws IOException
     {
         File source = File.createTempFile( "line-conversion-test-in.", "" );
         source.deleteOnExit();
         File dest = File.createTempFile( "line-conversion-test-out.", "" );
         dest.deleteOnExit();
-        
+
         FileWriter sourceWriter = null;
         StringReader sourceReader = new StringReader( test );
         try


Reply via email to