1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.release.plugin.mojos;
18
19 import static junit.framework.TestCase.assertTrue;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22
23 import java.io.File;
24
25 import org.apache.maven.api.plugin.testing.InjectMojo;
26 import org.apache.maven.api.plugin.testing.MojoTest;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35 @SuppressWarnings("deprecation")
36 @MojoTest
37 public class CommonsSiteCompressionMojoTest {
38
39 private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
40
41 @BeforeEach
42 public void setUp() throws Exception {
43 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
44 if (testingDirectory.exists()) {
45 FileUtils.deleteDirectory(testingDirectory);
46 }
47 }
48
49 @Test
50 @InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site-failure.xml")
51 public void testCompressSiteDirNonExistentFailure(final CommonsSiteCompressionMojo mojo) throws Exception {
52 try {
53 mojo.execute();
54 } catch (final MojoFailureException e) {
55 assertEquals(
56 "\"mvn site\" was not run before this goal, or a siteDirectory did not exist.", e.getMessage()
57 );
58 }
59 }
60
61 @Test
62 @InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site.xml")
63 public void testCompressSiteSuccess(final CommonsSiteCompressionMojo mojo) throws Exception {
64 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
65 testingDirectory.mkdir();
66 mojo.execute();
67 final File siteZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/site.zip");
68 assertTrue(siteZip.exists());
69 }
70
71 @Test
72 @InjectMojo(goal = "compress-site", pom = "src/test/resources/mojos/compress-site/compress-site-disabled.xml")
73 public void testDisabled(final CommonsSiteCompressionMojo mojo) throws Exception {
74 mojo.execute();
75 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
76 assertFalse(testingDirectory.exists());
77 }
78 }