Skip to content

Commit 42725b0

Browse files
committed
#783: add tests
1 parent e70100d commit 42725b0

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
import java.util.Map;
3434
import java.util.Properties;
3535
import java.util.TimeZone;
36+
import java.util.stream.Stream;
3637
import org.apache.maven.plugin.MojoExecutionException;
3738
import org.apache.maven.project.MavenProject;
3839
import org.codehaus.plexus.util.FileUtils;
3940
import org.eclipse.jgit.api.Git;
4041
import org.eclipse.jgit.api.ResetCommand;
4142
import org.junit.jupiter.params.ParameterizedTest;
43+
import org.junit.jupiter.params.provider.Arguments;
4244
import org.junit.jupiter.params.provider.MethodSource;
4345
import pl.project13.core.CommitIdPropertiesOutputFormat;
4446
import pl.project13.core.git.GitDescribeConfig;
@@ -237,9 +239,20 @@ public void shouldSkipDescribeWhenConfiguredToDoSo(boolean useNativeGit) throws
237239
.satisfies(new DoesNotContainKeyCondition("git.commit.id.describe"));
238240
}
239241

242+
static Stream<Arguments> useNativeGitWithBranches() {
243+
return useNativeGit().flatMap(arg ->
244+
Stream.of(
245+
"test_branch",
246+
"feature/my-git-branch"
247+
).map(str ->
248+
Arguments.of(arg.get()[0], str)
249+
)
250+
);
251+
}
252+
240253
@ParameterizedTest
241-
@MethodSource("useNativeGit")
242-
public void shouldNotUseBuildEnvironmentBranchInfoWhenParameterSet(boolean useNativeGit)
254+
@MethodSource("useNativeGitWithBranches")
255+
public void shouldNotUseBuildEnvironmentBranchInfoWhenParameterSet(boolean useNativeGit, String branchName)
243256
throws Exception {
244257
mavenSandbox
245258
.withParentProject("my-jar-project", "jar")
@@ -262,14 +275,14 @@ public void shouldNotUseBuildEnvironmentBranchInfoWhenParameterSet(boolean useNa
262275
// reset repo and force detached HEAD
263276
try (final Git git = git("my-jar-project")) {
264277
git.reset().setMode(ResetCommand.ResetType.HARD).setRef("b6a73ed").call();
265-
git.checkout().setCreateBranch(true).setName("test_branch").setForceRefUpdate(true).call();
278+
git.checkout().setCreateBranch(true).setName(branchName).setForceRefUpdate(true).call();
266279
}
267280

268281
// when
269282
mojo.execute();
270283

271284
// then
272-
assertPropertyPresentAndEqual(targetProject.getProperties(), "git.branch", "test_branch");
285+
assertPropertyPresentAndEqual(targetProject.getProperties(), "git.branch", branchName);
273286
}
274287

275288
@ParameterizedTest

src/test/java/pl/project13/maven/git/GitIntegrationTest.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Optional;
3333
import java.util.Properties;
3434
import java.util.concurrent.ThreadLocalRandom;
35+
import java.util.stream.Stream;
3536
import javax.annotation.Nonnull;
3637
import org.apache.commons.io.FileUtils;
3738
import org.apache.maven.execution.MavenSession;
@@ -40,6 +41,7 @@
4041
import org.eclipse.jgit.api.Git;
4142
import org.junit.jupiter.api.AfterEach;
4243
import org.junit.jupiter.api.BeforeEach;
44+
import org.junit.jupiter.params.provider.Arguments;
4345
import pl.project13.core.CommitIdPropertiesOutputFormat;
4446

4547
/**
@@ -53,8 +55,11 @@ public abstract class GitIntegrationTest {
5355
private static final boolean UseJGit = false;
5456
private static final boolean UseNativeGit = true;
5557

56-
public static Collection<?> useNativeGit() {
57-
return asList(UseJGit, UseNativeGit);
58+
public static Stream<Arguments> useNativeGit() {
59+
return Stream.of(
60+
Arguments.of(UseJGit),
61+
Arguments.of(UseNativeGit)
62+
);
5863
}
5964

6065
/** Sandbox directory with unique name for current test. */

src/test/java/pl/project13/maven/git/GitPropertiesFileTest.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
package pl.project13.maven.git;
2020

21-
import static java.util.Arrays.asList;
2221
import static org.assertj.core.api.Assertions.assertThat;
2322

2423
import java.io.File;
2524
import java.nio.charset.StandardCharsets;
26-
import java.util.Collection;
2725
import java.util.Properties;
26+
import java.util.stream.Stream;
2827
import org.apache.maven.project.MavenProject;
2928
import org.codehaus.plexus.util.FileUtils;
3029
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.Arguments;
3131
import org.junit.jupiter.params.provider.MethodSource;
3232
import pl.project13.core.CommitIdPropertiesOutputFormat;
3333
import pl.project13.core.util.GenericFileManager;
@@ -40,8 +40,11 @@ public class GitPropertiesFileTest extends GitIntegrationTest {
4040
static final boolean USE_JGIT = false;
4141
static final boolean USE_NATIVE_GIT = true;
4242

43-
public static Collection<?> useNativeGit() {
44-
return asList(USE_JGIT, USE_NATIVE_GIT);
43+
public static Stream<Arguments> useNativeGit() {
44+
return Stream.of(
45+
Arguments.of(USE_JGIT),
46+
Arguments.of(USE_NATIVE_GIT)
47+
);
4548
}
4649

4750
@ParameterizedTest

0 commit comments

Comments
 (0)