|
19 | 19 |
|
20 | 20 | import org.apache.maven.plugin.MojoExecutionException; |
21 | 21 | import org.apache.maven.project.MavenProject; |
22 | | -import org.fest.util.Files; |
| 22 | +import org.codehaus.plexus.util.FileUtils; |
23 | 23 | import org.junit.Test; |
| 24 | + |
| 25 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 26 | +import com.google.common.io.Files; |
24 | 27 | import pl.project13.maven.git.FileSystemMavenSandbox.CleanUp; |
25 | 28 | import pl.project13.test.utils.AssertException; |
26 | 29 |
|
27 | 30 | import java.io.File; |
| 31 | +import java.nio.charset.Charset; |
| 32 | +import java.util.HashMap; |
| 33 | +import java.util.Map; |
28 | 34 | import java.util.Properties; |
29 | 35 |
|
30 | 36 | import static org.fest.assertions.Assertions.assertThat; |
| 37 | +import static org.junit.Assert.assertEquals; |
31 | 38 | import static org.mockito.internal.util.reflection.Whitebox.setInternalState; |
32 | 39 |
|
33 | 40 | public class GitCommitIdMojoIntegrationTest extends GitIntegrationTest { |
@@ -128,31 +135,65 @@ public void run() throws Exception { |
128 | 135 | } |
129 | 136 |
|
130 | 137 | @Test |
131 | | - public void shouldGenerateCustomPropertiesFile() throws Exception { |
132 | | - // given |
133 | | - mavenSandbox.withParentProject("my-pom-project", "pom") |
134 | | - .withChildProject("my-jar-module", "jar") |
135 | | - .withGitRepoInChild(AvailableGitTestRepo.GIT_COMMIT_ID) |
136 | | - .create(CleanUp.CLEANUP_FIRST); |
| 138 | + public void shouldGenerateCustomPropertiesFileProperties() throws Exception { |
| 139 | + // given |
| 140 | + mavenSandbox.withParentProject("my-pom-project", "pom") |
| 141 | + .withChildProject("my-jar-module", "jar") |
| 142 | + .withGitRepoInChild(AvailableGitTestRepo.GIT_COMMIT_ID) |
| 143 | + .create(CleanUp.CLEANUP_FIRST); |
137 | 144 |
|
138 | | - MavenProject targetProject = mavenSandbox.getChildProject(); |
| 145 | + MavenProject targetProject = mavenSandbox.getChildProject(); |
139 | 146 |
|
140 | | - String targetFilePath = "target/classes/custom-git.properties"; |
141 | | - File expectedFile = new File(targetProject.getBasedir(), targetFilePath); |
| 147 | + String targetFilePath = "target/classes/custom-git.properties"; |
| 148 | + File expectedFile = new File(targetProject.getBasedir(), targetFilePath); |
142 | 149 |
|
143 | | - setProjectToExecuteMojoIn(targetProject); |
144 | | - alterMojoSettings("generateGitPropertiesFile", true); |
145 | | - alterMojoSettings("generateGitPropertiesFilename", targetFilePath); |
| 150 | + setProjectToExecuteMojoIn(targetProject); |
| 151 | + alterMojoSettings("generateGitPropertiesFile", true); |
| 152 | + alterMojoSettings("generateGitPropertiesFilename", targetFilePath); |
146 | 153 |
|
147 | | - // when |
148 | | - try { |
149 | | - mojo.execute(); |
150 | | - |
151 | | - // then |
152 | | - assertThat(expectedFile).exists(); |
153 | | - } finally { |
154 | | - Files.delete(expectedFile); |
155 | | - } |
| 154 | + // when |
| 155 | + try { |
| 156 | + mojo.execute(); |
| 157 | + |
| 158 | + // then |
| 159 | + assertThat(expectedFile).exists(); |
| 160 | + } finally { |
| 161 | + FileUtils.forceDelete(expectedFile); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void shouldGenerateCustomPropertiesFileJson() throws Exception { |
| 167 | + // given |
| 168 | + mavenSandbox.withParentProject("my-pom-project", "pom") |
| 169 | + .withChildProject("my-jar-module", "jar") |
| 170 | + .withGitRepoInChild(AvailableGitTestRepo.GIT_COMMIT_ID) |
| 171 | + .create(CleanUp.CLEANUP_FIRST); |
| 172 | + |
| 173 | + MavenProject targetProject = mavenSandbox.getChildProject(); |
| 174 | + |
| 175 | + String targetFilePath = "target/classes/custom-git.properties"; |
| 176 | + File expectedFile = new File(targetProject.getBasedir(), targetFilePath); |
| 177 | + |
| 178 | + setProjectToExecuteMojoIn(targetProject); |
| 179 | + alterMojoSettings("generateGitPropertiesFile", true); |
| 180 | + alterMojoSettings("generateGitPropertiesFilename", targetFilePath); |
| 181 | + alterMojoSettings("format", "json"); |
| 182 | + |
| 183 | + // when |
| 184 | + try { |
| 185 | + mojo.execute(); |
| 186 | + |
| 187 | + // then |
| 188 | + assertThat(expectedFile).exists(); |
| 189 | + String json = Files.toString(expectedFile, Charset.defaultCharset()); |
| 190 | + ObjectMapper om = new ObjectMapper(); |
| 191 | + Map<String, String> map = new HashMap<String, String>(); |
| 192 | + map = om.readValue(expectedFile, map.getClass()); |
| 193 | + assertThat(map.size() > 10); |
| 194 | + } finally { |
| 195 | + FileUtils.forceDelete(expectedFile); |
| 196 | + } |
156 | 197 | } |
157 | 198 |
|
158 | 199 | private void alterMojoSettings(String parameterName, Object parameterValue) { |
|
0 commit comments