Package com.pogofish.jadt.maven

Source Code of com.pogofish.jadt.maven.JADTMojoTest

package com.pogofish.jadt.maven;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.Collections;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.junit.Test;

import com.pogofish.jadt.JADT;
import com.pogofish.jadt.errors.SemanticError;
import com.pogofish.jadt.errors.SyntaxError;
import com.pogofish.jadt.sink.StringSinkFactoryFactory;

/**
* Unit tests for the JADTMojo
*
* @author jiry
*
*/
public class JADTMojoTest {
    /**
     * Make sure that everything works on the happy path
     */
    @Test
    public void testHappy() throws Exception {
        final File srcFile = new File(JADT.TEST_SRC_INFO);
        final File destDir = new File(JADT.TEST_DIR);
 
        final JADTMojo mojo = new JADTMojo();
        final StringSinkFactoryFactory factory = new StringSinkFactoryFactory();       
        mojo.jadt = JADT.createDummyJADT(Collections.<SyntaxError>emptyList(), Collections.<SemanticError>emptyList(), srcFile.getCanonicalPath(), factory);
       
        mojo.setSrcPath(srcFile);
        mojo.setDestDir(destDir);
        mojo.setProject(new MavenProject());
        mojo.execute();
       
        final String result = factory.results().get(destDir.getCanonicalPath()).get(0).getResults().get(JADT.TEST_CLASS_NAME);
        assertEquals(JADT.TEST_SRC_INFO, result);
        assertEquals(1, mojo.project.getCompileSourceRoots().size());
        assertEquals(destDir.getCanonicalPath(), mojo.project.getCompileSourceRoots().get(0));
    }
   
    /**
     * Make sure that exceptions are handled properly
     */
    @Test
    public void testException() throws Exception {
        final File srcFile = new File(JADT.TEST_SRC_INFO);
        final File destDir = new File(JADT.TEST_DIR);
       
        final JADTMojo mojo = new JADTMojo();
        final StringSinkFactoryFactory factory = new StringSinkFactoryFactory();       
        mojo.jadt = JADT.createDummyJADT(Collections.<SyntaxError>emptyList(), Collections.<SemanticError>singletonList(SemanticError._DuplicateConstructor("whatever", "something")), srcFile.getCanonicalPath(), factory);
       
        mojo.setSrcPath(srcFile);
        mojo.setDestDir(destDir);
        mojo.setProject(new MavenProject());
       
        try {
            mojo.execute();

            final String result = factory.results().get(destDir.getCanonicalPath()).get(0).getResults().get(JADT.TEST_CLASS_NAME);
            fail("Did not get exception, got " + result);
        } catch (MojoExecutionException e) {
            // yay
        }
    }
   
   
}
TOP

Related Classes of com.pogofish.jadt.maven.JADTMojoTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.