package de.is24.deadcode4j.plugin;

import de.is24.deadcode4j.AnalysisStage;
import de.is24.deadcode4j.DeadCode;
import org.apache.maven.plugin.logging.Log;
import org.junit.Before;
import org.junit.Test;

import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;

import static java.util.Arrays.asList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class A_DeadCodeLogger {

    private final Collection<String> noClasses = Collections.emptyList();
    private DeadCodeLogger objectUnderTest;
    private Log logMock;

    private static Collection<String> classes(String... classes) {
        return asList(classes);
    }

    @Before
    public void setUpMojo() {
        logMock = mock(Log.class);
        objectUnderTest = new DeadCodeLogger(logMock);
    }

    @Test
    public void logsThatNoDeadCodeWasFound() throws Exception {
        DeadCode deadCode = new DeadCode(noExceptions(), classes("A", "B"), noClasses);

        objectUnderTest.log(deadCode);

        verifyNumberOfAnalyzedClassesIs(2);
        verifyNoDeadCodeWasFound();
    }

    @Test
    public void logsThatOneDeadClassOfThreeWasFound() throws Exception {
        DeadCode deadCode = new DeadCode(noExceptions(), classes("A", "B", "SingleClass"), classes("SingleClass"));

        objectUnderTest.log(deadCode);

        verifyNumberOfAnalyzedClassesIs(3);
        verify(logMock).warn("Found 1 unused class(es):");
        verify(logMock).warn("  SingleClass");
    }

    @Test
    public void logsThatAnExceptionOccurred() {
        DeadCode deadCode = new DeadCode(exceptionAt(AnalysisStage.FILE_ANALYSIS), noClasses, noClasses);

        objectUnderTest.log(deadCode);

        verify(logMock).warn("At least one file could not be parsed; analysis may be inaccurate!");
    }

    private EnumSet<AnalysisStage> noExceptions() {
        return EnumSet.noneOf(AnalysisStage.class);
    }

    private EnumSet<AnalysisStage> exceptionAt(AnalysisStage fileAnalysis) {
        return EnumSet.of(fileAnalysis);
    }

    private void verifyNumberOfAnalyzedClassesIs(int count) {
        verify(logMock).info("Analyzed " + count + " class(es).");
    }

    private void verifyNoDeadCodeWasFound() {
        verify(logMock).info("No unused classes found. Rejoice!");
    }

}

@@ -355,19 +355,106 @@
 to.M
-ockito.mock
+atchers.anyString;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times
 ;%0Aim
@@ -1656,21 +1656,39 @@
 Occurred
+DuringFileAnalysis
 () %7B%0A
-
         
@@ -1852,83 +1852,892 @@
 Mock
-).warn(%22At least one file could not be parsed; analysis may be inaccurate!%22
+, times(1)).warn(anyString());%0A    %7D%0A%0A    @Test%0A    public void logsThatAnExceptionOccurredDuringGeneralSetup() %7B%0A        DeadCode deadCode = new DeadCode(exceptionAt(AnalysisStage.GENERAL_SETUP), noClasses, noClasses);%0A%0A        objectUnderTest.log(deadCode);%0A%0A        verify(logMock, times(1)).error(anyString());%0A    %7D%0A%0A    @Test%0A    public void logsThatAnExceptionOccurredDuringModuleSetup() %7B%0A        DeadCode deadCode = new DeadCode(exceptionAt(AnalysisStage.MODULE_SETUP), noClasses, noClasses);%0A%0A        objectUnderTest.log(deadCode);%0A%0A        verify(logMock, times(1)).warn(anyString());%0A    %7D%0A%0A    @Test%0A    public void logsThatAnExceptionOccurredDuringDeadCodeAnalysis() %7B%0A        DeadCode deadCode = new DeadCode(exceptionAt(AnalysisStage.DEADCODE_ANALYSIS), noClasses, noClasses);%0A%0A        objectUnderTest.log(deadCode);%0A%0A        verify(logMock, times(1)).warn(anyString()
 );%0A 

increase coverage