/*
 * Licensed 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.
 */

package io.github.zlika.reproducible;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Assert;
import org.junit.Test;

/**
 * Unit tests for {@link ZipStripper}.
 */
public class ZipStripperTest
{
    /**
     * Tests stripping on a reference JAR file.
     * @throws IOException
     */
    @Test
    public void testStripZip() throws IOException
    {
    	final String testJarName;
    	final String strippedJarName;
    	// Results are different on Linux and Windows because of line endings,
    	// so we use different test files
    	if (System.getProperty("line.separator").length() == 1)
    	{
    		testJarName = "test-jar-lf.jar";
    		strippedJarName = "test-jar-lf-stripped.jar";
    	}
    	else
    	{
    		testJarName = "test-jar-crlf.jar";
    		strippedJarName = "test-jar-crlf-stripped.jar";
    	}
    	
        try (final InputStream is = this.getClass().getResourceAsStream(testJarName);
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                final InputStream expectedIs = this.getClass().getResourceAsStream(strippedJarName))
        {
            new ZipStripper(new File("target/reproducible-maven-plugin/" + this.getClass().getName()))
                .addFileStripper("META-INF/MANIFEST.MF", new ManifestStripper())
                .addFileStripper("META-INF/maven/org.test/test/pom.properties", new PomPropertiesStripper())
                .strip(is, os);
            final byte[] expected = new byte[expectedIs.available()];
            expectedIs.read(expected);
            Assert.assertArrayEquals(expected, os.toByteArray());
        }
    }
}

@@ -996,25 +996,28 @@
 n%0A    %7B%0A    
-%09
+    
 final String
@@ -1034,17 +1034,20 @@
 me;%0A    
-%09
+    
 final St
@@ -1072,17 +1072,20 @@
 me;%0A    
-%09
+    
 // Resul
@@ -1151,17 +1151,20 @@
 gs,%0A    
-%09
+    
 // so we
@@ -1193,17 +1193,20 @@
 les%0A    
-%09
+    
 if (Syst
@@ -1225,53 +1225,71 @@
 ty(%22
-line.separator%22).length() == 1
+os.name%22).toLowerCase().contains(%22win%22)
 )%0A    
-%09
+    
 %7B%0A    
-%09%09
+        
 test
@@ -1308,16 +1308,18 @@
 est-jar-
+cr
 lf.jar%22;
@@ -1315,34 +1315,40 @@
 -crlf.jar%22;%0A    
-%09%09
+        
 strippedJarName 
@@ -1359,16 +1359,18 @@
 est-jar-
+cr
 lf-strip
@@ -1383,24 +1383,30 @@
 r%22;%0A    
-%09%7D%0A
+    %7D%0A   
     
-%09
+ 
 else%0A   
@@ -1410,17 +1410,26 @@
     
-%09
+    
 %7B%0A    
-%09%09
+        
 test
@@ -1440,34 +1440,32 @@
 ame = %22test-jar-
-cr
 lf.jar%22;%0A    %09%09s
@@ -1465,10 +1465,16 @@
     
-%09%09
+        
 stri
@@ -1489,34 +1489,32 @@
 ame = %22test-jar-
-cr
 lf-stripped.jar%22
@@ -1523,16 +1523,22 @@
     
-%09
+    
 %7D%0A    
+ 
-%09
+   
 %0A   

Fix Travis CI build.