package de.is24.deadcode4j.plugin;

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;

import java.io.File;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class IT_PuttingItAllTogether extends AbstractMojoTestCase {

    private Log logMock;
    private FindDeadCodeMojo findDeadCodeMojo;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        File pom = getTestFile("target/test-classes/de/is24/deadcode4j/plugin/projects/pom.xml");
        assertNotNull(pom);
        assertTrue(pom.exists());

        findDeadCodeMojo = (FindDeadCodeMojo) lookupMojo("find", pom);
        assertNotNull(findDeadCodeMojo);

        logMock = mock(Log.class);
        findDeadCodeMojo.setLog(logMock);
    }

    public void test() throws Exception {
        findDeadCodeMojo.execute();

        verify(logMock).info("Analyzed 13 class(es).");
        verify(logMock).info("Ignoring 1 class(es) which seem(s) to be unused.");
        verify(logMock).warn("Class [com.acme.Foo] should be ignored, but is not dead. You should remove the configuration entry.");
        verify(logMock).warn("Found 2 unused class(es):");
        verify(logMock).warn("  DeadServlet");
        verify(logMock).warn("  SingleClass");
    }

}

@@ -29,16 +29,62 @@
 lugin;%0A%0A
+import org.apache.maven.plugin.MojoExecution;%0A
 import o
@@ -184,28 +184,109 @@
 se;%0A
-%0Aimport java.io.File
+import org.codehaus.plexus.util.ReflectionUtils;%0A%0Aimport java.io.File;%0Aimport java.lang.reflect.Field
 ;%0A%0Ai
@@ -940,16 +940,255 @@
 gMock);%0A
+        Field mojoExecution = ReflectionUtils.getFieldByNameIncludingSuperclasses(%22mojoExecution%22, FindDeadCodeMojo.class);%0A        mojoExecution.setAccessible(true);%0A        mojoExecution.set(findDeadCodeMojo, mock(MojoExecution.class));%0A
     %7D%0A%0A 

fix test