package ca.coglinc.gradle.plugins.javacc;

import java.util.HashMap;
import java.util.Map;

import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class JavaccPluginTest {
    private Project project;

    @Before
    public void applyJavaccPluginToProject() {
        project = ProjectBuilder.builder().build();
        Map<String, String> pluginNames = new HashMap<String, String>(1);
        pluginNames.put("plugin", "ca.coglinc.javacc");

        project.apply(pluginNames);
    }

    @Test
    public void pluginAddsCompileJavaccTaskToProject() {
        final Task compileJavaccTask = project.getTasks().getByName("compileJavacc");
        Assert.assertNotNull(compileJavaccTask);
        Assert.assertTrue(compileJavaccTask instanceof CompileJavaccTask);
    }

    @Test
    public void pluginAddsCompileJJTreeTaskToProject() {
        final Task compileJJTreeTask = project.getTasks().getByName("compileJjtree");
        Assert.assertNotNull(compileJJTreeTask);
        Assert.assertTrue(compileJJTreeTask instanceof CompileJjTreeTask);
    }
    
    @Test
    public void pluginAddsCompileJjdocTaskToProject() {
        final Task compileJjdocTask = project.getTasks().getByName("jjdoc");
        Assert.assertNotNull(compileJjdocTask);
        Assert.assertTrue(compileJjdocTask instanceof CompileJjdocTask);
    }
}

@@ -47,47 +47,88 @@
 ort 
-java.util.HashMap;%0Aimport java.util.Map
+static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue
 ;%0A%0Ai
@@ -185,16 +185,63 @@
 i.Task;%0A
+import org.gradle.api.artifacts.Configuration;%0A
 import o
@@ -283,33 +283,8 @@
 er;%0A
-import org.junit.Assert;%0A
 impo
@@ -360,16 +360,49 @@
 nTest %7B%0A
+    private JavaccPlugin plugin;%0A
     priv
@@ -474,32 +474,69 @@
 inToProject() %7B%0A
+        plugin = new JavaccPlugin();%0A
         project 
@@ -571,24 +571,25 @@
 uild();%0A
+%0A
         
 Map%3CStri
@@ -584,164 +584,28 @@
     
-Map%3CString, String%3E pluginNames = new HashMap%3CString, String%3E(1);%0A        pluginNames.put(%22plugin%22, %22ca.coglinc.javacc%22);%0A%0A        project.apply(pluginNames
+plugin.apply(project
 );%0A 
@@ -759,32 +759,33 @@
 leJavacc%22);%0A
+%0A
         
 Assert.asser
@@ -764,39 +764,32 @@
 acc%22);%0A%0A        
-Assert.
 assertNotNull(co
@@ -806,39 +806,32 @@
 cTask);%0A        
-Assert.
 assertTrue(compi
@@ -1030,32 +1030,33 @@
 leJjtree%22);%0A
+%0A
         
 Assert.asser
@@ -1035,39 +1035,32 @@
 ree%22);%0A%0A        
-Assert.
 assertNotNull(co
@@ -1077,39 +1077,32 @@
 eTask);%0A        
-Assert.
 assertTrue(compi
@@ -1151,20 +1151,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Te
@@ -1295,24 +1295,25 @@
 jdoc%22);%0A
+%0A
         
 Assert.a
@@ -1300,31 +1300,24 @@
 );%0A%0A        
-Assert.
 assertNotNul
@@ -1345,23 +1345,16 @@
         
-Assert.
 assertTr
@@ -1408,11 +1408,245 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void pluginDefinesDefaultDependencyOnJavacc() %7B%0A        Configuration javaccDependencyConfiguration = project.getConfigurations().getByName(%22javacc%22);%0A%0A        assertNotNull(javaccDependencyConfiguration);%0A    %7D
 %0A%7D%0A

Add unit test to verify javacc dependency configuration