Skip to content

Commit

Permalink
[MSHARED-1306] Use fixtures to reduice duplicate code (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored Oct 10, 2023
1 parent 860e40e commit c90cc8c
Showing 1 changed file with 12 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@

import org.apache.maven.shared.utils.Os;
import org.apache.maven.shared.utils.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DefaultInvokerTest {

private Invoker invoker = newInvoker();
private InvocationRequest request = new DefaultInvocationRequest();

@BeforeEach
public void setUp() throws Exception {
request.setDebug(true);
request.setProperties(getProperties());
}

@Test
public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setDebug(true);
request.setGoals(Arrays.asList("clean", "package"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -55,14 +59,8 @@ public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxE
@Test
public void testBuildShouldFail() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setDebug(true);
request.setGoals(Arrays.asList("clean", "package"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -72,15 +70,9 @@ public void testBuildShouldFail() throws MavenInvocationException, URISyntaxExce
@Test
public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setDebug(true);
request.setGoals(Arrays.asList("clean", "package"));
request.setTimeoutInSeconds(4);
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -99,15 +91,9 @@ public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxE
@Test
public void testSpacePom() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setPomFileName("pom with spaces.xml");
request.setDebug(true);
request.setGoals(Collections.singletonList("clean"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -117,15 +103,9 @@ public void testSpacePom() throws Exception {
@Test
public void testSpaceAndSpecialCharPom() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setPomFileName("pom with spaces & special char.xml");
request.setDebug(true);
request.setGoals(Collections.singletonList("clean"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -135,15 +115,9 @@ public void testSpaceAndSpecialCharPom() throws Exception {
@Test
public void testSpaceSettings() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setUserSettingsFile(new File(basedir, "settings with spaces.xml"));
request.setDebug(true);
request.setGoals(Collections.singletonList("validate"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -153,15 +127,9 @@ public void testSpaceSettings() throws Exception {
@Test
public void testSpaceLocalRepo() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setLocalRepositoryDirectory(new File(basedir, "repo with spaces"));
request.setDebug(true);
request.setGoals(Collections.singletonList("validate"));
request.setProperties(getProperties());

InvocationResult result = invoker.execute(request);

Expand All @@ -171,17 +139,11 @@ public void testSpaceLocalRepo() throws Exception {
@Test
public void testSpaceProperties() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);

Properties props = getProperties();
props.setProperty("key", "value with spaces");
props.setProperty("key with spaces", "value");
request.setProperties(props);
request.setDebug(true);
request.setGoals(Collections.singletonList("validate"));

InvocationResult result = invoker.execute(request);
Expand All @@ -191,15 +153,9 @@ public void testSpaceProperties() throws Exception {

@Test
public void testPomOutsideProject() throws Exception {
File testDir = getBasedirForBuild();

File basedir = new File(testDir, "project");
File pom = new File(testDir, "temp/pom.xml");

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
File pom = new File(basedir, "temp/pom.xml");
request.setPomFile(pom);
request.setGoals(Collections.singletonList("validate"));

Expand All @@ -211,10 +167,6 @@ public void testPomOutsideProject() throws Exception {
@Test
public void testMavenWrapperInProject() throws Exception {
File basedir = getBasedirForBuild();

Invoker invoker = newInvoker();

InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(basedir);
request.setGoals(Collections.singletonList("test-wrapper-goal"));
request.setMavenExecutable(new File("./mvnw"));
Expand Down

0 comments on commit c90cc8c

Please sign in to comment.