package osm.jp.gpx;
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import static org.hamcrest.CoreMatchers.is;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
+import static osm.jp.gpx.Restamp.TIME_PATTERN;
/**
*
@Before
public void setUp() {
+ dirPath = "./src/test/data/images";
}
@After
public void tearDown() {
}
- /**
- * Test of main method, of class Restamp.
- */
+ String dirPath;
+
@Test
public void testMain() {
+ String[] ans = {
+ "2019-09-01 16:26:51 JST",
+ "2019-09-01 16:26:56 JST",
+ "2019-09-01 16:27:01 JST",
+ "2019-09-01 16:27:06 JST",
+ "2019-09-01 16:27:11 JST",
+ };
+
+ try {
+ String[] argv = new String[]{
+ dirPath,
+ "00001.jpg",
+ "2019-09-01 16:26:51 JST",
+ "00003.jpg",
+ "2019-09-01 16:27:01 JST"
+ };
+ Restamp.main(argv);
+ check(new File(dirPath), ans);
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testMain_2() {
+ String[] ans = {
+ "2019-09-02 16:26:53 JST",
+ "2019-09-02 16:26:56 JST",
+ "2019-09-02 16:26:58 JST",
+ "2019-09-02 16:27:01 JST",
+ "2019-09-02 16:27:03 JST",
+ };
+
+ try {
+ String[] argv = new String[]{
+ dirPath,
+ "00002.jpg",
+ "2019-09-02 16:26:56 JST",
+ "00004.jpg",
+ "2019-09-02 16:27:01 JST"
+ };
+ Restamp.main(argv);
+ check(new File(dirPath), ans);
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testMain_3() {
+ String[] ans = {
+ "2019-09-03 16:26:53 JST",
+ "2019-09-03 16:26:55 JST",
+ "2019-09-03 16:26:58 JST",
+ "2019-09-03 16:27:00 JST",
+ "2019-09-03 16:27:03 JST",
+ };
+
try {
- System.out.println("main");
String[] argv = new String[]{
- "/home/yuu/Desktop/OSM/20180325_横浜新道/img",
- "000033.jpg",
- "2018-03-25_12:20:32",
- "003752.jpg",
- "2018-03-25_13:22:42"
+ dirPath,
+ "00001.jpg",
+ "2019-09-03 16:26:53 JST",
+ "00003.jpg",
+ "2019-09-03 16:26:58 JST"
};
Restamp.main(argv);
+ check(new File(dirPath), ans);
}
catch (Exception e) {
fail();
}
}
+
+ @Test
+ public void testMain_4() {
+ String[] ans = {
+ "2019-09-04 16:26:53 JST",
+ "2019-09-04 16:26:55 JST",
+ "2019-09-04 16:26:58 JST",
+ "2019-09-04 16:27:00 JST",
+ "2019-09-04 16:27:03 JST",
+ };
+
+ try {
+ String[] argv = new String[]{
+ dirPath,
+ "00003.jpg",
+ "2019-09-04 16:26:58 JST",
+ "00005.jpg",
+ "2019-09-04 16:27:03 JST"
+ };
+ Restamp.main(argv);
+ check(new File(dirPath), ans);
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+
+ void check(File imgDir, String[] ans) {
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+
+ File[] files = imgDir.listFiles();
+ java.util.Arrays.sort(files, (File file1, File file2) -> file1.getName().compareTo(file2.getName()));
+
+ int i = 0;
+ for (File jpgFile : files) {
+ long msec = jpgFile.lastModified();
+ String lastModifiedStr = df.format(new Date(msec));
+ assertThat(lastModifiedStr, is(ans[i]));
+ i++;
+ }
+
+ }
}