Skip to content

Commit

Permalink
[#323] create test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarwell committed Jul 21, 2022
1 parent 463b97e commit 11f6800
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<email>sjaranowski@apache.org</email>
<timezone>Europe/Warsaw</timezone>
</developer>
<developer>
<id>bmarwell</id>
<name>Benjamin Marwell</name>
<email>bmarwell@apache.org</email>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>

<contributors>
Expand Down
2 changes: 2 additions & 0 deletions src/it/projects/mexec-323/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = compile
invoker.debug = true
42 changes: 42 additions & 0 deletions src/it/projects/mexec-323/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<artifactId>mexec-323</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mkdir</executable>
<arguments>
<argument>-p</argument>
<argument>dist/emails</argument>
</arguments>
<workingDirectory>src/build</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.codehaus.mojo.exec;

import static java.util.Collections.emptyMap;

/*
* Copyright 2005 The Codehaus. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
Expand All @@ -12,6 +14,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -295,6 +298,24 @@ public void testParseCommandlineOSWin()
assertEquals( javaHome, args[0] );
}


public void test_exec_receives_all_parameters() throws MojoExecutionException
{
// given
ExecMojo execMojo = new ExecMojo();
execMojo.setExecutable( "mkdir" );
execMojo.setArguments( Arrays.asList( "-p", "dist/mails" ) );
execMojo.setBasedir( new File("target") );

// when
final CommandLine commandLine = execMojo.getExecutablePath( emptyMap(), new File( "target" ) );
execMojo.execute();

// then
assertTrue( "dir should have been created",
Paths.get( "target", "dist", "mails" ).toFile().exists() );
}

private void checkMojo( String expectedCommandLine )
{
assertEquals( 1, mojo.getAmountExecutedCommandLines() );
Expand Down

0 comments on commit 11f6800

Please sign in to comment.