1   package com.atlassian.maven.plugins.amps.codegen.prompter;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.io.InputStream;
6   import java.util.UUID;
7   
8   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
9   
10  import org.apache.commons.io.FileUtils;
11  import org.apache.commons.io.IOUtils;
12  import org.codehaus.plexus.components.interactivity.Prompter;
13  import org.junit.After;
14  import org.junit.Before;
15  
16  import static org.mockito.Mockito.mock;
17  
18  /**
19   * @since 3.5
20   */
21  public abstract class AbstractPrompterTest
22  {
23      protected File tempDir;
24      protected File srcDir;
25      protected File testDir;
26      protected File resourcesDir;
27      protected File templateDir;
28      protected File pluginXml;
29      protected PluginModuleLocation moduleLocation;
30      protected Prompter prompter;
31  
32      @Before
33      public void setupDirs() throws Exception
34      {
35  
36          final File sysTempDir = new File("target");
37          String dirName = UUID.randomUUID()
38                  .toString();
39          tempDir = new File(sysTempDir, dirName);
40          srcDir = new File(tempDir, "src");
41          testDir = new File(tempDir, "test-src");
42          resourcesDir = new File(tempDir, "resources");
43          templateDir = new File(resourcesDir, "templates");
44          pluginXml = new File(resourcesDir, "atlassian-plugin.xml");
45  
46          tempDir.mkdirs();
47          srcDir.mkdirs();
48          resourcesDir.mkdirs();
49          templateDir.mkdirs();
50  
51          InputStream is = this.getClass()
52                  .getResourceAsStream("/empty-plugin.xml");
53          IOUtils.copy(is, FileUtils.openOutputStream(pluginXml));
54  
55          moduleLocation = new PluginModuleLocation.Builder(srcDir)
56                  .resourcesDirectory(resourcesDir)
57                  .testDirectory(testDir)
58                  .templateDirectory(templateDir)
59                  .build();
60          prompter = mock(Prompter.class);
61      }
62  
63      @After
64      public void removeTempDir() throws IOException
65      {
66          FileUtils.deleteDirectory(tempDir);
67      }
68  }