|
| 1 | +/* |
| 2 | + * This file is part of git-commit-id-plugin by Konrad Malawski <konrad.malawski@java.pl> |
| 3 | + * |
| 4 | + * git-commit-id-plugin is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * git-commit-id-plugin is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with git-commit-id-plugin. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package pl.project13.maven.git; |
| 19 | + |
| 20 | +import com.google.common.collect.ImmutableList; |
| 21 | +import com.google.common.collect.Maps; |
| 22 | +import org.apache.maven.project.MavenProject; |
| 23 | +import org.eclipse.jgit.lib.Repository; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import java.io.File; |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.Map; |
| 30 | +import java.util.Properties; |
| 31 | + |
| 32 | +import static org.fest.assertions.Assertions.assertThat; |
| 33 | +import static org.mockito.Mockito.*; |
| 34 | + |
| 35 | +/** |
| 36 | + * @author Adam Batkin |
| 37 | + */ |
| 38 | +public class GitCommitIdMojoDirtyFilesTest { |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testDetectCleanWorkingDirectory() throws Exception { |
| 42 | + File dotGitDirectory = AvailableGitTestRepo.GIT_WITH_NO_CHANGES.getDir(); |
| 43 | + GitDescribeConfig gitDescribeConfig = new GitDescribeConfig(); |
| 44 | + gitDescribeConfig.setSkip(false); |
| 45 | + |
| 46 | + String prefix = "git"; |
| 47 | + int abbrevLength = 7; |
| 48 | + String dateFormat = "dd.MM.yyyy '@' HH:mm:ss z"; |
| 49 | + boolean verbose = true; |
| 50 | + |
| 51 | + GitCommitIdMojo mojo = new GitCommitIdMojo(); |
| 52 | + mojo.setDotGitDirectory(dotGitDirectory); |
| 53 | + mojo.setPrefix(prefix); |
| 54 | + mojo.setAbbrevLength(abbrevLength); |
| 55 | + mojo.setDateFormat(dateFormat); |
| 56 | + mojo.setVerbose(verbose); |
| 57 | + mojo.useNativeGit(false); |
| 58 | + mojo.setGitDescribe(gitDescribeConfig); |
| 59 | + |
| 60 | + |
| 61 | + mojo.runningTests = true; |
| 62 | + mojo.project = mock(MavenProject.class, RETURNS_MOCKS); |
| 63 | + when(mojo.project.getPackaging()).thenReturn("jar"); |
| 64 | + |
| 65 | + mojo.execute(); |
| 66 | + |
| 67 | + Properties properties = mojo.getProperties(); |
| 68 | + |
| 69 | + assertThat(properties.get("git.commit.files.dirty")).isEqualTo("false"); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testDetectDirtyWorkingDirectory() throws Exception { |
| 74 | + File dotGitDirectory = AvailableGitTestRepo.GIT_WITH_CHANGES.getDir(); |
| 75 | + GitDescribeConfig gitDescribeConfig = new GitDescribeConfig(); |
| 76 | + gitDescribeConfig.setSkip(false); |
| 77 | + |
| 78 | + String prefix = "git"; |
| 79 | + int abbrevLength = 7; |
| 80 | + String dateFormat = "dd.MM.yyyy '@' HH:mm:ss z"; |
| 81 | + boolean verbose = true; |
| 82 | + |
| 83 | + GitCommitIdMojo mojo = new GitCommitIdMojo(); |
| 84 | + mojo.setDotGitDirectory(dotGitDirectory); |
| 85 | + mojo.setPrefix(prefix); |
| 86 | + mojo.setAbbrevLength(abbrevLength); |
| 87 | + mojo.setDateFormat(dateFormat); |
| 88 | + mojo.setVerbose(verbose); |
| 89 | + mojo.useNativeGit(false); |
| 90 | + mojo.setGitDescribe(gitDescribeConfig); |
| 91 | + |
| 92 | + |
| 93 | + mojo.runningTests = true; |
| 94 | + mojo.project = mock(MavenProject.class, RETURNS_MOCKS); |
| 95 | + when(mojo.project.getPackaging()).thenReturn("jar"); |
| 96 | + |
| 97 | + mojo.execute(); |
| 98 | + |
| 99 | + Properties properties = mojo.getProperties(); |
| 100 | + |
| 101 | + assertThat(properties.get("git.commit.files.dirty")).isEqualTo("true"); |
| 102 | + } |
| 103 | +} |
0 commit comments