Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-1306] Use fixtures to reduce duplicate code #67

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
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