OSDN Git Service

JUnit test AppParameters.java
authorhayashi <hayashi.yuu@gmail.com>
Tue, 16 May 2017 11:42:45 +0000 (20:42 +0900)
committerhayashi <hayashi.yuu@gmail.com>
Tue, 16 May 2017 11:42:45 +0000 (20:42 +0900)
importPicture/.classpath
importPicture/AdjustTime.ini [new file with mode: 0644]
importPicture/test/osm/jp/gpx/AppParametersTest.java [new file with mode: 0644]
importPicture/testdata/AdjustTime.null.ini [new file with mode: 0644]
importPicture/testdata/AdjustTime.off.ini [new file with mode: 0644]
importPicture/testdata/AdjustTime.on.ini [new file with mode: 0644]

index 775996d..3c1aed2 100644 (file)
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="test"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="lib/commons-imaging-1.0-20170205.201009-115.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
        <classpathentry kind="output" path="classes"/>
 </classpath>
diff --git a/importPicture/AdjustTime.ini b/importPicture/AdjustTime.ini
new file mode 100644 (file)
index 0000000..e23b51f
--- /dev/null
@@ -0,0 +1,16 @@
+#defuilt settings
+#Tue May 16 15:59:01 JST 2017
+GPX.BASETIME=FILE_UPDATE
+IMG.OUTPUT_EXIF=true
+GPX.OUTPUT_SPEED=false
+GPX.OUTPUT_WPT=false
+IMG.OUTPUT_ALL=false
+GPX.noFirstNode=true
+IMG.OUTPUT=true
+GPX.gpxSplit=true
+GPX.REUSE=false
+GPX.OVERWRITE_MAGVAR=false
+IMG.BASE_FILE=
+IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
diff --git a/importPicture/test/osm/jp/gpx/AppParametersTest.java b/importPicture/test/osm/jp/gpx/AppParametersTest.java
new file mode 100644 (file)
index 0000000..65e3a27
--- /dev/null
@@ -0,0 +1,204 @@
+package osm.jp.gpx;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.nio.channels.FileChannel;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.experimental.runners.*;
+
+@RunWith(Enclosed.class)
+public class AppParametersTest {
+       
+       public static class 定義ファイルが存在しない場合 {
+               AppParameters params;
+               
+               @Before
+               public void setUp() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       
+                       if (orgFile.exists()) {
+                               orgFile.delete();
+                       }
+                       if (iniFile.exists()) {
+                               iniFile.renameTo(orgFile);
+                       }
+                       params = new AppParameters();
+               }
+               
+               @After
+               public void tearDown() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       if (iniFile.exists()) {
+                               iniFile.delete();
+                       }
+                       if (orgFile.exists()) {
+                               orgFile.renameTo(iniFile);
+                       }
+               }
+               
+               @Test
+               public void IMG_OUTPUT_ALLが定義されていない時() {
+                       try {
+                               String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
+                               assertThat(valueStr, is("false"));
+                       }
+                       catch (Exception e) {
+                               fail("Exceptionが発生した。");
+                       }
+               }
+       }
+
+       public static class 定義ファイルがtureに定義されているとき {
+               
+               @Before
+               public void setUp() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       File testFile = new File("testdata", "AdjustTime.on.ini");
+                       
+                       if (orgFile.exists()) {
+                               orgFile.delete();
+                       }
+                       if (iniFile.exists()) {
+                               iniFile.renameTo(orgFile);
+                       }
+                       
+                       FileInputStream inStream = new FileInputStream(testFile);
+                       FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini"));
+               FileChannel inChannel = inStream.getChannel();
+               FileChannel outChannel = outStream.getChannel();
+               try {
+                   inChannel.transferTo(0, inChannel.size(),outChannel);
+               }
+               finally {
+                   if (inChannel != null) inChannel.close();
+                   if (outChannel != null) outChannel.close();
+                   inStream.close();
+                   outStream.close();
+               }
+               }
+               
+               @After
+               public void tearDown() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       if (iniFile.exists()) {
+                               iniFile.delete();
+                       }
+                       if (orgFile.exists()) {
+                               orgFile.renameTo(iniFile);
+                       }
+               }
+               
+               @Test
+               public void IMG_OUTPUT_ALLがtureに定義されているとき() {
+                       try {
+                               AppParameters params;
+                               params = new AppParameters();
+                               String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
+                               assertThat(valueStr, is("true"));
+                       }
+                       catch (Exception e) {
+                               fail("Exceptionが発生した。");
+                       }
+               }
+               
+               @Test
+               public void IMG_OUTPUT_ALLをfalseに書き換える() {
+                       try {
+                               AppParameters params = new AppParameters();
+                               params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+                               params.store();
+                               params = null;
+                               AppParameters newParams = new AppParameters();
+                               String valueStr = newParams.getProperty(AppParameters.IMG_OUTPUT_ALL);
+                               assertThat(valueStr, is("false"));
+                       }
+                       catch (Exception e) {
+                               fail("Exceptionが発生した。");
+                       }
+               }
+       }
+
+       public static class 定義ファイルがfalseに定義されているとき {
+               
+               @Before
+               public void setUp() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       File testFile = new File("testdata", "AdjustTime.off.ini");
+                       
+                       if (orgFile.exists()) {
+                               orgFile.delete();
+                       }
+                       if (iniFile.exists()) {
+                               iniFile.renameTo(orgFile);
+                       }
+
+                       FileInputStream inStream = new FileInputStream(testFile);
+                       FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini"));
+               FileChannel inChannel = inStream.getChannel();
+               FileChannel outChannel = outStream.getChannel();
+               try {
+                   inChannel.transferTo(0, inChannel.size(),outChannel);
+               }
+               finally {
+                   if (inChannel != null) inChannel.close();
+                   if (outChannel != null) outChannel.close();
+                   inStream.close();
+                   outStream.close();
+               }
+               }
+               
+               @After
+               public void tearDown() throws Exception {
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       if (iniFile.exists()) {
+                               iniFile.delete();
+                       }
+                       if (orgFile.exists()) {
+                               orgFile.renameTo(iniFile);
+                       }
+               }
+               
+               @Test
+               public void IMG_OUTPUT_ALLがfalseに定義されているとき() {
+                       try {
+                               AppParameters params = new AppParameters();
+                               String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL);
+                               assertThat(valueStr, is("false"));
+                       }
+                       catch (Exception e) {
+                               fail("Exceptionが発生した。");
+                       }
+               }
+               
+               @Test
+               public void IMG_OUTPUT_ALLをtrueに書き換える() {
+                       try {
+                               AppParameters params = new AppParameters();
+                               params.setProperty(AppParameters.IMG_OUTPUT_ALL, "true");
+                               params.store();
+                               params = null;
+                               AppParameters newParams = new AppParameters();
+                               String valueStr = newParams.getProperty(AppParameters.IMG_OUTPUT_ALL);
+                               assertThat(valueStr, is("true"));
+                       }
+                       catch (Exception e) {
+                               fail("Exceptionが発生した。");
+                       }
+               }
+       }
+
+}
diff --git a/importPicture/testdata/AdjustTime.null.ini b/importPicture/testdata/AdjustTime.null.ini
new file mode 100644 (file)
index 0000000..7b60e49
--- /dev/null
@@ -0,0 +1,16 @@
+#defuilt settings
+#Tue May 16 15:59:01 JST 2017
+GPX.BASETIME=
+IMG.OUTPUT_EXIF=
+GPX.OUTPUT_SPEED=
+GPX.OUTPUT_WPT=
+IMG.OUTPUT_ALL=
+GPX.noFirstNode=
+IMG.OUTPUT=
+GPX.gpxSplit=
+GPX.REUSE=
+GPX.OVERWRITE_MAGVAR=
+IMG.BASE_FILE=
+IMG.SOURCE_FOLDER=
+GPX.SOURCE_FOLDER=
+IMG.OUTPUT_FOLDER=
diff --git a/importPicture/testdata/AdjustTime.off.ini b/importPicture/testdata/AdjustTime.off.ini
new file mode 100644 (file)
index 0000000..3494d77
--- /dev/null
@@ -0,0 +1,16 @@
+#defuilt settings
+#Tue May 16 15:59:01 JST 2017
+GPX.BASETIME=FILE_UPDATE
+IMG.OUTPUT_EXIF=false
+GPX.OUTPUT_SPEED=false
+GPX.OUTPUT_WPT=false
+IMG.OUTPUT_ALL=false
+GPX.noFirstNode=false
+IMG.OUTPUT=false
+GPX.gpxSplit=false
+GPX.REUSE=false
+GPX.OVERWRITE_MAGVAR=false
+IMG.BASE_FILE=
+IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
diff --git a/importPicture/testdata/AdjustTime.on.ini b/importPicture/testdata/AdjustTime.on.ini
new file mode 100644 (file)
index 0000000..8a9a96b
--- /dev/null
@@ -0,0 +1,16 @@
+#defuilt settings
+#Tue May 16 15:59:01 JST 2017
+GPX.BASETIME=FILE_UPDATE
+IMG.OUTPUT_EXIF=true
+GPX.OUTPUT_SPEED=true
+GPX.OUTPUT_WPT=true
+IMG.OUTPUT_ALL=true
+GPX.noFirstNode=true
+IMG.OUTPUT=true
+GPX.gpxSplit=true
+GPX.REUSE=true
+GPX.OVERWRITE_MAGVAR=true
+IMG.BASE_FILE=
+IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.