diff --git a/src/test/java/pl/project13/maven/git/BigDiffTest.java b/src/test/java/pl/project13/maven/git/BigDiffTest.java index b06d2318..bdfaeb93 100644 --- a/src/test/java/pl/project13/maven/git/BigDiffTest.java +++ b/src/test/java/pl/project13/maven/git/BigDiffTest.java @@ -86,23 +86,6 @@ public void bigDiff() throws Exception { assertGitPropertiesPresentInProject(targetProject.getProperties()); } - private void assertGitPropertiesPresentInProject(final Properties properties) { - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.describe")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); - } - private GitDescribeConfig createGitDescribeConfig( final boolean forceLongFormat, final int abbrev) { final GitDescribeConfig gitDescribeConfig = new GitDescribeConfig(); diff --git a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java index 28d93d10..4bba944c 100644 --- a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java +++ b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java @@ -18,7 +18,6 @@ package pl.project13.maven.git; -import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.mockito.Mockito.when; @@ -26,7 +25,6 @@ import java.io.File; import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -49,17 +47,6 @@ @RunWith(JUnitParamsRunner.class) public class GitCommitIdMojoIntegrationTest extends GitIntegrationTest { - private static final boolean UseJGit = false; - private static final boolean UseNativeGit = true; - - public static Collection useNativeGit() { - return asList(UseJGit, UseNativeGit); - } - - public static Collection useDirty() { - return asList(true, false); - } - @Test @Parameters(method = "useNativeGit") public void shouldIncludeExpectedProperties(boolean useNativeGit) throws Exception { @@ -1731,28 +1718,4 @@ private GitDescribeConfig createGitDescribeConfig(boolean forceLongFormat, int a gitDescribeConfig.setDirty(""); return gitDescribeConfig; } - - private void assertPropertyPresentAndEqual(Properties properties, String key, String expected) { - assertThat(properties.stringPropertyNames()).contains(key); - assertThat(properties.getProperty(key)).isEqualTo(expected); - } - - private void assertGitPropertiesPresentInProject(Properties properties) { - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.describe")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.commit.count")); - } } diff --git a/src/test/java/pl/project13/maven/git/GitIntegrationTest.java b/src/test/java/pl/project13/maven/git/GitIntegrationTest.java index 0beca07d..8c8b4fab 100644 --- a/src/test/java/pl/project13/maven/git/GitIntegrationTest.java +++ b/src/test/java/pl/project13/maven/git/GitIntegrationTest.java @@ -18,16 +18,15 @@ package pl.project13.maven.git; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Properties; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; import org.apache.commons.io.FileUtils; @@ -47,6 +46,13 @@ public abstract class GitIntegrationTest { private static final String SANDBOX_DIR = "target" + File.separator + "sandbox" + File.separator; protected static final String evaluateOnCommit = "HEAD"; + private static final boolean UseJGit = false; + private static final boolean UseNativeGit = true; + + public static Collection useNativeGit() { + return asList(UseJGit, UseNativeGit); + } + /** Sandbox directory with unique name for current test. */ private String currSandbox; @@ -156,4 +162,31 @@ private static List getReactorProjects(@Nonnull MavenProject proje } return reactorProjects; } + + public static void assertPropertyPresentAndEqual( + Properties properties, String key, String expected) { + assertThat(properties.stringPropertyNames()).contains(key); + assertThat(properties.getProperty(key)).isEqualTo(expected); + } + + public static void assertGitPropertiesPresentInProject(Properties properties) { + assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.describe")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.committer.time")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.author.time")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.name")); + assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.commit.count")); + } } diff --git a/src/test/java/pl/project13/maven/git/GitPropertiesFileTest.java b/src/test/java/pl/project13/maven/git/GitPropertiesFileTest.java index bc463ad8..f0c0af15 100644 --- a/src/test/java/pl/project13/maven/git/GitPropertiesFileTest.java +++ b/src/test/java/pl/project13/maven/git/GitPropertiesFileTest.java @@ -108,25 +108,4 @@ public void shouldConformPropertiesFileWhenSpecialCharactersInValueString(boolea } } } - - private void assertGitPropertiesPresentInProject(Properties properties) { - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.describe")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.committer.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.author.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.closest.tag.commit.count")); - } } diff --git a/src/test/java/pl/project13/maven/git/GitSubmodulesTest.java b/src/test/java/pl/project13/maven/git/GitSubmodulesTest.java index d7efba59..d47a7f34 100644 --- a/src/test/java/pl/project13/maven/git/GitSubmodulesTest.java +++ b/src/test/java/pl/project13/maven/git/GitSubmodulesTest.java @@ -18,22 +18,23 @@ package pl.project13.maven.git; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; import java.nio.file.Files; -import java.util.Properties; -import javax.annotation.Nonnull; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; import org.apache.maven.project.MavenProject; import org.junit.Test; +import org.junit.runner.RunWith; /** * Testcases to verify that the git-commit-id-plugin works properly. */ +@RunWith(JUnitParamsRunner.class) public class GitSubmodulesTest extends GitIntegrationTest { @Test - public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject() throws Exception { + @Parameters(method = "useNativeGit") + public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject(boolean useNativeGit) throws Exception { mavenSandbox .withParentProject("my-jar-project", "jar") .withGitRepoInParent(AvailableGitTestRepo.WITH_SUBMODULES) @@ -42,6 +43,7 @@ public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject() throws Ex MavenProject targetProject = mavenSandbox.getChildProject(); setProjectToExecuteMojoIn(targetProject); + mojo.useNativeGit = useNativeGit; // when mojo.execute(); @@ -51,7 +53,8 @@ public void shouldResolvePropertiesOnDefaultSettingsForNonPomProject() throws Ex } @Test - public void shouldGeneratePropertiesWithSubmodules() throws Exception { + @Parameters(method = "useNativeGit") + public void shouldGeneratePropertiesWithSubmodules(boolean useNativeGit) throws Exception { // given mavenSandbox .withParentProject("my-pom-project", "pom") @@ -68,34 +71,12 @@ public void shouldGeneratePropertiesWithSubmodules() throws Exception { "gitdir: ../.git/modules/remote-module".getBytes() ); - mojo.useNativeGit = true; // FIXME: make me a parameter + mojo.useNativeGit = useNativeGit; // when mojo.execute(); // then - assertGitPropertiesPresentInProject(targetProject.getProperties()); - assertThat(targetProject.getProperties().getProperty("git.commit.id.abbrev")).isEqualTo("945bfe6"); - } - - public void setProjectToExecuteMojoIn(@Nonnull MavenProject project) { - mojo.project = project; - mojo.dotGitDirectory = new File(project.getBasedir(), ".git"); - } - - private void assertGitPropertiesPresentInProject(Properties properties) { - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); + assertPropertyPresentAndEqual(targetProject.getProperties(), "git.commit.id.abbrev", "945bfe6"); } } diff --git a/src/test/java/pl/project13/maven/git/NaivePerformanceTest.java b/src/test/java/pl/project13/maven/git/NaivePerformanceTest.java index e9de42ed..802d62e9 100644 --- a/src/test/java/pl/project13/maven/git/NaivePerformanceTest.java +++ b/src/test/java/pl/project13/maven/git/NaivePerformanceTest.java @@ -94,23 +94,4 @@ private GitDescribeConfig createGitDescribeConfig(boolean forceLongFormat, int a gitDescribeConfig.setAbbrev(abbrev); return gitDescribeConfig; } - - private void assertGitPropertiesPresentInProject(Properties properties) { - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.host")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.branch")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.abbrev")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.id.describe")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.build.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.name")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.user.email")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.full")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.message.short")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.author.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.commit.committer.time")); - assertThat(properties).satisfies(new ContainsKeyCondition("git.remote.origin.url")); - } } diff --git a/src/test/java/pl/project13/maven/git/NativeAndJGitProviderTest.java b/src/test/java/pl/project13/maven/git/NativeAndJGitProviderTest.java index 215c5439..4c35a98c 100644 --- a/src/test/java/pl/project13/maven/git/NativeAndJGitProviderTest.java +++ b/src/test/java/pl/project13/maven/git/NativeAndJGitProviderTest.java @@ -186,10 +186,4 @@ private Properties createCopy(Properties orig) { return p; } - - private void assertGitPropertiesPresentInProject(Properties properties) { - for (String key : GIT_KEYS) { - assertThat(properties).satisfies(new ContainsKeyCondition(key)); - } - } }