OSDN Git Service

テストメソッドの名称を日本語からアルファベットに変更した
[importpicture/importpicture.git] / src / test / java / osm / jp / gpx / ImportPictureTest.java
1 package osm.jp.gpx;
2
3 import static org.junit.Assert.*;
4
5 import java.io.File;
6 import java.io.FileInputStream;
7 import java.io.FileOutputStream;
8 import java.io.IOException;
9 import java.nio.channels.FileChannel;
10 import org.junit.runner.*;
11 import org.junit.experimental.theories.DataPoints;
12 import org.junit.experimental.theories.Theories;
13 import org.junit.experimental.theories.Theory;
14
15 @RunWith(Theories.class)
16 public class ImportPictureTest {
17
18     @DataPoints
19     public static Fixture[] datas = Fixture.datas;
20
21     /**
22      * パラメータテスト
23      * @param dataset
24      * @throws Exception
25      */
26     @Theory
27     public void testParameter(Fixture dataset) throws Exception {
28         setup(dataset);
29         testdo(dataset.iniFilePath);
30         Expecter.check(dataset);
31     }
32
33     void setup(Fixture dataset) throws IOException {
34         System.out.println(dataset.toString());
35
36         // カメラディレクトリを削除する
37         File dir = new File("target/test-classes/cameradata");
38         if (dir.exists()) {
39             UnZip.delete(dir);
40         }
41         File outDir = new File("target/test-classes/output");
42         if (outDir.exists()) {
43                 UnZip.delete(outDir);
44         }
45         outDir.mkdir();
46
47         // カメラディレクトリを作成する
48         UnZip.uncompress(new File(dataset.tarFilePath), new File("target/test-classes/cameradata"));
49
50         // GPXファイルをセット
51         //copy(new File(dataset.gpxSourcePath), new File(dataset.gpxDestinationPath));
52     }
53     
54     void copy(File source, File dest) throws IOException {
55         if (source.isDirectory()) {
56                 File[] files = source.listFiles();
57                 for (int i = 0; i < files.length; i++) {
58                                 File file = files[i];
59                                 copy(file, dest);
60                         }
61         }
62         else {
63             try (FileInputStream inStream = new FileInputStream(source);
64                 FileOutputStream outStream = new FileOutputStream(dest);
65                 FileChannel inChannel = inStream.getChannel();
66                 FileChannel outChannel = outStream.getChannel())
67             {
68                 inChannel.transferTo(0, inChannel.size(), outChannel);
69             }
70         }
71     }
72
73     /**
74      * 実行する
75      * @throws Exception
76      */
77     void testdo(String iniFilePath) {
78         try {
79             String[] argv = {iniFilePath};
80             ImportPicture.main(argv);
81         }
82         catch (Exception e) {
83             e.printStackTrace();
84             fail("Exceptionが発生した。");
85         }
86     }
87 }