package com.nitorcreations;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.File;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

public class DomainMapperMojoTest {
    @Spy
    File outputDirectory = new File("");
    @Spy
    List<String> packages = new ArrayList<String>();
    @Mock
    MavenProject project;
    @Mock
    SafeWriter writer;
    @Mock
    DomainMapperFactory factory;
    @Mock
    DomainMapper mapper;
    @InjectMocks
    DomainMapperMojo mojo = new DomainMapperMojo();
    final List<Class<?>> dummyList = Arrays.<Class<?>> asList(String.class, Integer.class);

    @Before
    public void setup() throws ClassNotFoundException {
        MockitoAnnotations.initMocks(this);
        when(factory.create(any(List.class), any(URLClassLoader.class))).thenReturn(mapper);
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Test
    public void testExecute() throws MojoExecutionException, ClassNotFoundException, MojoFailureException {
        packages.add("foo.bar");
        mojo.execute();
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
        verify(factory).create(captor.capture(), any(URLClassLoader.class));
        assertThat((List<String>) captor.getValue(), hasItems("foo.bar"));
    }
}

@@ -368,16 +368,88 @@
 .List;%0A%0A
+import org.apache.maven.artifact.DependencyResolutionRequiredException;%0A
 import o
@@ -1255,16 +1255,51 @@
 lass);%0A%0A
+    @SuppressWarnings(%22unchecked%22)%0A
     @Bef
@@ -1347,32 +1347,71 @@
 otFoundException
+, DependencyResolutionRequiredException
  %7B%0A        Mocki
@@ -1534,16 +1534,109 @@
 apper);%0A
+        when(project.getCompileClasspathElements()).thenReturn(Arrays.asList(%22foo%22, %22bar%22));%0A
     %7D%0A%0A 
@@ -2092,11 +2092,492 @@
 );%0A    %7D
+%0A%0A    @Test(expected = MojoFailureException.class)%0A    public void failsWithNoPackagesDefined() throws MojoExecutionException, ClassNotFoundException, MojoFailureException %7B%0A        mojo.execute();%0A    %7D%0A%0A    @Test(expected = MojoFailureException.class)%0A    public void failsWhenClassNotFound() throws MojoExecutionException, ClassNotFoundException, MojoFailureException %7B%0A        when(mapper.describeDomain()).thenThrow(new ClassNotFoundException());%0A        mojo.execute();%0A    %7D
 %0A%7D%0A

add few more tests