3 import static org.junit.Assert.*;
6 import java.io.FileInputStream;
7 import java.io.FileOutputStream;
8 import java.io.IOException;
9 import java.nio.channels.FileChannel;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.junit.experimental.runners.*;
17 @RunWith(Enclosed.class)
18 public class AppParametersTest {
20 public static class 定義ファイルが存在しない場合 {
23 public void setUp() throws Exception {
24 delTestData("AdjustTime.ini");
28 public void tearDown() throws Exception {
29 delTestData("AdjustTime.ini");
33 public void IMG_OUTPUT_ALLが定義されていない時() {
35 AppParameters params = new AppParameters("target/test-classes/AdjustTime.off.ini");
36 String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
37 assertFalse(Boolean.getBoolean(valueStr));
40 fail("Exceptionが発生した。");
45 public static class 定義ファイルがtureに定義されているとき {
48 public void setUp() throws Exception {
49 delTestData("AdjustTime.ini");
50 setupTestData("AdjustTime.on.ini", "AdjustTime.ini");
54 public void tearDown() throws Exception {
55 delTestData("AdjustTime.ini");
59 public void IMG_OUTPUT_ALLがtureに定義されているとき() {
61 AppParameters params = new AppParameters();
62 String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
63 assertTrue(Boolean.valueOf(valueStr));
66 fail("Exceptionが発生した。");
71 public void IMG_OUTPUT_ALLをfalseに書き換える() {
73 AppParameters params = new AppParameters();
74 params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
76 AppParameters newParams = new AppParameters();
77 String valueStr = newParams.getProperty(AppParameters.IMG_OUTPUT_ALL);
78 assertFalse(Boolean.valueOf(valueStr));
81 fail("Exceptionが発生した。");
86 public static class 定義ファイルがfalseに定義されているとき {
89 public void setUp() throws Exception {
90 delTestData("AdjustTime.ini");
91 setupTestData("AdjustTime.off.ini", "AdjustTime.ini");
95 public void tearDown() throws Exception {
96 delTestData("AdjustTime.ini");
100 public void IMG_OUTPUT_ALLがfalseに定義されているとき() {
102 AppParameters params = new AppParameters();
103 String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
104 assertFalse(Boolean.valueOf(valueStr));
106 catch (Exception e) {
107 fail("Exceptionが発生した。");
112 public void IMG_OUTPUT_ALLをtrueに書き換える() {
114 AppParameters params = new AppParameters();
115 params.setProperty(AppParameters.IMG_OUTPUT_ALL, "true");
117 AppParameters newParams = new AppParameters();
118 String valueStr = newParams.getProperty(AppParameters.IMG_OUTPUT_ALL);
119 assertTrue(Boolean.valueOf(valueStr));
121 catch (Exception e) {
122 fail("Exceptionが発生した。");
127 public static void delTestData(String filename) {
128 File iniFile = new File(filename);
129 if (iniFile.exists()) {
134 static void setupTestData(String sfilename, String dfilename) throws IOException {
135 File testFile = new File("target/test-classes/ini", sfilename);
136 FileInputStream inStream = new FileInputStream(testFile);
137 FileOutputStream outStream = new FileOutputStream(new File(dfilename));
138 FileChannel inChannel = inStream.getChannel();
139 FileChannel outChannel = outStream.getChannel();
141 inChannel.transferTo(0, inChannel.size(),outChannel);
144 if (inChannel != null) inChannel.close();
145 if (outChannel != null) outChannel.close();