Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,11 @@
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand Down
70 changes: 47 additions & 23 deletions src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* @author Jerome Lacoste
* @version $Id$
*/
public class ExecJavaMojoTest extends AbstractMojoTestCase {
class ExecJavaMojoTest extends AbstractMojoTestCase {
@Mock
private MavenSession session;

Expand All @@ -64,7 +71,8 @@ public class ExecJavaMojoTest extends AbstractMojoTestCase {
*
* @throws Exception if any exception occurs
*/
public void testRunnable() throws Exception {
@Test
void runnable() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project19/pom.xml");
ExecJavaMojo mojo = (ExecJavaMojo) lookupMojo("java", pom);
setUpProject(pom, mojo);
Expand All @@ -83,69 +91,77 @@ public void testRunnable() throws Exception {
*
* @throws Exception if any exception occurs
*/
public void testSimpleRun() throws Exception {
@Test
void simpleRun() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project4/pom.xml");

String output = execute(pom, "java");

assertEquals("Hello" + System.getProperty("line.separator"), output);
}

public void testJSR512InstanceMainNoArgs() throws Exception {
@Test
void jsr512InstanceMainNoArgs() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project22/pom.xml");

String output = execute(pom, "java");

assertEquals("Correct choice" + System.getProperty("line.separator"), output);
}

public void testJSR512PrefersStringArrayArgs() throws Exception {
@Test
void jsr512PrefersStringArrayArgs() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project23/pom.xml");

String output = execute(pom, "java");

assertEquals("Correct choice arg1 arg2" + System.getProperty("line.separator"), output);
}

public void testJSR512StaticMainNoArgs() throws Exception {
@Test
void jsr512StaticMainNoArgs() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project24/pom.xml");

String output = execute(pom, "java");

assertEquals("Correct choice" + System.getProperty("line.separator"), output);
}

public void testJSR512PackagePrivateStaticMainNoArgs() throws Exception {
@Test
void jsr512PackagePrivateStaticMainNoArgs() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project27/pom.xml");

String output = execute(pom, "java");

assertEquals("Correct choice" + System.getProperty("line.separator"), output);
}

public void testJSR512PackagePrivateStaticMainWithArgs() throws Exception {
@Test
void jsr512PackagePrivateStaticMainWithArgs() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project28/pom.xml");

String output = execute(pom, "java");

assertEquals("Correct choice arg1 arg2" + System.getProperty("line.separator"), output);
}

public void testJSR512FailureInstanceMainPrivateNoArgsConstructor() throws Exception {
@Test
void jsr512FailureInstanceMainPrivateNoArgsConstructor() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project25/pom.xml");
try {
execute(pom, "java");
fail("Expected Exception to be thrown but none was thrown");
} catch (Throwable e) {
assertTrue(e instanceof MojoExecutionException);
assertInstanceOf(MojoExecutionException.class, e);

assertEquals(
"The specified mainClass doesn't contain a main method with appropriate signature.",
e.getCause().getMessage());
}
}

public void testJSR512InheritedMain() throws Exception {
@Test
void jsr512InheritedMain() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project26/pom.xml");

String output = execute(pom, "java");
Expand All @@ -160,15 +176,16 @@ public void testJSR512InheritedMain() throws Exception {
*
* @throws Exception if any exception occurs
*/
public void testEmptySystemProperty() throws Exception {
@Test
void emptySystemProperty() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project5/pom.xml");

assertNull("System property not yet created", System.getProperty("test.name"));
assertNull(System.getProperty("test.name"), "System property not yet created");

assertEquals("Hello " + System.lineSeparator(), execute(pom, "java"));

// ensure we get back in the original state and didn't leak the execution config
assertNull("System property not yet created", System.getProperty("test.name"));
assertNull(System.getProperty("test.name"), "System property not yet created");
}

/**
Expand All @@ -178,17 +195,18 @@ public void testEmptySystemProperty() throws Exception {
* @author Lukasz Cwik
* @throws Exception if any exception occurs
*/
public void testRunWhichThrowsExceptionIsNotWrappedInInvocationTargetException() throws Exception {
@Test
void runWhichThrowsExceptionIsNotWrappedInInvocationTargetException() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project15/pom.xml");

try {
execute(pom, "java");

fail("Expected Exception to be thrown but none was thrown");
} catch (Throwable e) {
assertTrue(e instanceof MojoExecutionException);
assertInstanceOf(MojoExecutionException.class, e);

assertTrue(e.getCause() instanceof IOException);
assertInstanceOf(IOException.class, e.getCause());

assertEquals("expected IOException thrown by test", e.getCause().getMessage());
}
Expand Down Expand Up @@ -243,7 +261,8 @@ public void testRunWhichThrowsExceptionIsNotWrappedInInvocationTargetException()
*
* @throws Exception if any exception occurs
*/
public void testWaitNoDaemonThreads() throws Exception {
@Test
void waitNoDaemonThreads() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project7/pom.xml");

String output = execute(pom, "java");
Expand All @@ -258,7 +277,8 @@ public void testWaitNoDaemonThreads() throws Exception {
*
* @throws Exception if any exception occurs
*/
public void testWaitNonInterruptibleDaemonThreads() throws Exception {
@Test
void waitNonInterruptibleDaemonThreads() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project9/pom.xml");

String output = execute(pom, "java");
Expand All @@ -274,7 +294,8 @@ public void testWaitNonInterruptibleDaemonThreads() throws Exception {
*
* @throws Exception if any exception occurs
*/
public void testUncooperativeThread() throws Exception {
@Test
void uncooperativeThread() throws Exception {
// FIXME:
// This will fail the test, because Assume is a JUnit 4 thing, but we are running in JUnit 3 mode, because
// AbstractMojoTestCase extends PlexusTestCase extends TestCase. The latter is a JUnit 3 compatibility class.
Expand Down Expand Up @@ -311,7 +332,8 @@ public void testUncooperativeThread() throws Exception {
* Test the commandline parsing facilities of the {@link AbstractExecMojo} class
* @throws Exception if any exception occurs
*/
public void testRunWithArgs() throws Exception {
@Test
void runWithArgs() throws Exception {

String resultString = execute(new File(getBasedir(), "src/test/projects/project8/pom.xml"), "java");

Expand All @@ -324,7 +346,8 @@ public void testRunWithArgs() throws Exception {
* Ensures that classpath can be filtered (exclude from plugin deps or project deps) to resolve conflicts.
* @throws Exception if something unexpected occurs.
*/
public void testExcludedClasspathElement() throws Exception {
@Test
void excludedClasspathElement() throws Exception {
String LS = System.getProperty("line.separator");

// slf4j-simple
Expand Down Expand Up @@ -355,7 +378,8 @@ public void testExcludedClasspathElement() throws Exception {
*
* @throws Exception if any exception occurs
*/
public void testProjectProperties() throws Exception {
@Test
void projectProperties() throws Exception {
File pom = new File(getBasedir(), "src/test/projects/project18/pom.xml");

String output = execute(pom, "java");
Expand Down
Loading
Loading