OSDN Git Service

fixed: maven test
[importpicture/importpicture.git] / src / test / java / osm / jp / gpx / ImportPictureUnitTest.java
1 package osm.jp.gpx;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.*;
5
6 import java.io.File;
7
8 import org.junit.runner.*;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.junit.experimental.runners.*;
12
13 @RunWith(Enclosed.class)
14 public class ImportPictureUnitTest {
15
16     public static class 出力ディレクトリが存在しないとき {
17         
18         @Before
19         public void setUp() throws Exception {
20                 Fixture dataset = Fixture.datas[0];
21             System.out.println(dataset.toString());
22
23             // カメラディレクトリを削除する
24             File dir = new File("target/test-classes/cameradata");
25             if (dir.exists()) {
26                 UnZip.delete(dir);
27             }
28             File outDir = new File("target/test-classes/output");
29             if (outDir.exists()) {
30                 UnZip.delete(outDir);
31             }
32             //outDir.mkdir();
33
34             // カメラディレクトリを作成する
35             UnZip.uncompress(new File(dataset.tarFilePath), new File("target/test-classes/cameradata"));
36         }
37
38
39         @Test
40         public void 実行() throws Exception {
41                 Fixture dataset = Fixture.datas[0];
42             try {
43                 ImportPictureUnitTest.testdo(dataset.iniFilePath);
44             }
45             catch (Exception e) {
46                 e.printStackTrace();
47                 fail("Exceptionが発生した。");
48             }
49
50             AppParameters params = new AppParameters(dataset.iniFilePath);
51             File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER));
52             assertThat(outDir.exists(), is(true));
53             
54             Expecter.check(dataset);
55         }
56
57         @Test
58         public void MAGVARをON() throws Exception {
59                 Fixture dataset = Fixture.datas[1];
60             try {
61                 ImportPictureUnitTest.testdo(dataset.iniFilePath);
62             }
63             catch (Exception e) {
64                 e.printStackTrace();
65                 fail("Exceptionが発生した。");
66             }
67
68             AppParameters params = new AppParameters(dataset.iniFilePath);
69             File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER));
70             assertThat(outDir.exists(), is(true));
71             
72             Expecter.check(dataset);
73         }
74
75         static String comparePosition(double b) {
76             return String.format("%.4f", b);
77         }
78     }
79
80     public static class 出力ディレクトリがFILEのとき {
81         
82         @Before
83         public void setUp() throws Exception {
84                 Fixture dataset = Fixture.datas[0];
85             System.out.println(dataset.toString());
86
87             // カメラディレクトリを削除する
88             File dir = new File("target/test-classes/cameradata");
89             if (dir.exists()) {
90                 UnZip.delete(dir);
91             }
92             File outDir = new File("target/test-classes/output");
93             if (outDir.exists()) {
94                 UnZip.delete(outDir);
95             }
96             
97             // ファイルを生成
98             outDir.createNewFile();
99
100             // カメラディレクトリを作成する
101             UnZip.uncompress(new File(dataset.tarFilePath), new File("target/test-classes/cameradata"));
102         }
103
104
105         @Test
106         public void 実行() throws Exception {
107                 Fixture dataset = Fixture.datas[0];
108                 try {
109                 ImportPictureUnitTest.testdo(dataset.iniFilePath);
110                 fail("outDirがFILEなのに、例外が発生しなかった");        // 例外が発生しなかった
111                 }
112                 catch (Exception e) {
113                         // 例外が発生する
114                         assertThat(true, is(true));
115                 }
116
117             AppParameters params = new AppParameters(dataset.iniFilePath);
118             File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER));
119             assertThat(outDir.exists(), is(true));
120         }
121
122         static String comparePosition(double b) {
123             return String.format("%.4f", b);
124         }
125     }
126
127     
128     /**
129      * 実行する
130      * @throws Exception
131      */
132     static void testdo(String iniFilePath) throws Exception {
133         String[] argv = {iniFilePath};
134         ImportPicture.main(argv);
135     }
136 }