package com.izforge.izpack.installer.data;

import com.izforge.izpack.api.data.AutomatedInstallData;
import com.izforge.izpack.api.substitutor.VariableSubstitutor;
import com.izforge.izpack.compiler.container.TestInstallationContainer;
import com.izforge.izpack.matcher.ZipMatcher;
import com.izforge.izpack.test.Container;
import com.izforge.izpack.test.InstallFile;
import com.izforge.izpack.test.junit.PicoRunner;
import com.izforge.izpack.util.IoHelper;
import org.hamcrest.core.Is;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;

import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Test of unpacker
 */
@RunWith(PicoRunner.class)
@Container(TestInstallationContainer.class)
public class UninstallWriteTest
{
    private UninstallDataWriter uninstallDataWriter;
    private AutomatedInstallData idata;
    private VariableSubstitutor variableSubstitutor;

    public UninstallWriteTest(UninstallDataWriter uninstallDataWriter, VariableSubstitutor variableSubstitutor, AutomatedInstallData idata)
    {
        this.uninstallDataWriter = uninstallDataWriter;
        this.variableSubstitutor = variableSubstitutor;
        this.idata = idata;
    }

    @Test
    @InstallFile("samples/basicInstall/basicInstall.xml")
    public void testWriteUninstaller() throws Exception
    {
        uninstallDataWriter.write();

        String dest = IoHelper.translatePath(idata.getInfo().getUninstallerPath(), variableSubstitutor);
        String jar = dest + File.separator + idata.getInfo().getUninstallerName();
        File uninstallJar = new File(jar);
        assertThat(uninstallJar.exists(), Is.is(true));
        assertThat(uninstallJar, ZipMatcher.isZipContainingFiles("com/izforge/izpack/uninstaller/Destroyer.class",
                "langpack.xml", "META-INF/MANIFEST.MF", " com/izforge/izpack/gui/IconsDatabase.class"));

    }
}

@@ -455,37 +455,8 @@
 er;%0A
-import org.hamcrest.core.Is;%0A
 impo
@@ -530,16 +530,56 @@
 .File;%0A%0A
+import static org.hamcrest.core.Is.is;%0A%0A
 import s
@@ -1592,24 +1592,33 @@
  File(jar);%0A
+        %0A
         asse
@@ -1647,19 +1647,16 @@
 ists(), 
-Is.
 is(true)
@@ -1658,16 +1658,25 @@
 true));%0A
+        %0A
         
@@ -1678,32 +1678,45 @@
      assertThat(
+%0A            
 uninstallJar, Zi
@@ -1713,16 +1713,29 @@
 allJar, 
+%0A            
 ZipMatch
@@ -1758,16 +1758,33 @@
 ngFiles(
+%0A                
 %22com/izf
@@ -1857,16 +1857,33 @@
 k.xml%22, 
+%0A                
 %22META-IN
@@ -1902,10 +1902,26 @@
 F%22, 
+%0A                
 %22
- 
 com/
@@ -1959,16 +1959,50 @@
 e.class%22
+,%0A                %22/img/trash.png%22
 ));%0A%0A   

Test case enhanced for missing icon files in the uninstaller.