3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.notNullValue;
5 import static org.hamcrest.CoreMatchers.nullValue;
6 import static org.junit.Assert.*;
7 import java.text.DateFormat;
8 import java.text.ParseException;
9 import java.text.SimpleDateFormat;
10 import java.util.Date;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.experimental.runners.Enclosed;
16 import org.junit.runner.RunWith;
18 @RunWith(Enclosed.class)
19 public class ElementMapTRKPTTest {
21 public static class Keyのみ {
22 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
23 ElementMapTRKPT map = null;
25 static String[] values = {
26 "1970-01-01 08:59:59.999",
27 "1970-01-01 09:00:00.000",
28 "1970-01-01 09:00:00.001",
29 "2018-10-25 07:59:59.999",
30 "2018-10-25 08:00:00.000",
31 "2018-10-25 08:00:00.001"
35 public void setUp() throws Exception {
36 timeL = (sdf.parse("2018-10-25 08:00:00.000")).getTime();
37 map = new ElementMapTRKPT(new AppParameters(AppParameters.FILE_PATH));
38 map.put(new Date(timeL), null); // 5-6: 2018-10-25 08:00:00.000
39 map.put(new Date(timeL + 1L), null); // 7: 2018-10-25 08:00:00.001
40 map.put(new Date(timeL - 1L), null); // 4: 2018-10-25 07:59:59.999
41 map.put(new Date(1L), null); // 3: 1970-01-01 09:00:00.001
42 map.put(new Date(0L), null); // 2: 1970-01-01 09:00:00.000
43 map.put(new Date(-1L), null); // 1: 1970-01-01 08:59:59.999
44 map.put(new Date(timeL), null); // 5-6: 2018-10-25 08:00:00.000
48 public void tearDown() throws Exception {
49 AppParametersTest.delTestData("AdjustTime.ini");
53 public void 同一キーをPUTした場合() {
54 assertThat(map.size(), is(6));
58 public void イテレータを使って読みだす() {
59 assertThat(map.size(), is(6));
62 for (Date key : map.keySet()) {
63 assertThat(sdf.format(key), is(values[i++]));
68 public void 拡張FOR文を使って読みだす() {
69 assertThat(map.size(), is(6));
72 for (Date key : map.keySet()) {
73 assertThat(sdf.format(key), is(values[i++]));
78 public static class Keyとvalueのセット {
79 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
80 ElementMapTRKPT map = null;
84 * <trkpt lat="35.8812697884" lon="137.9952202085"><time>2017-05-29T01:23:18Z</time></trkpt>
85 * <trkpt lat="35.8811769169" lon="137.9951928835"><time>2017-05-29T01:23:21Z</time><ele>614.90</ele></trkpt>
86 * <trkpt lat="35.881112963" lon="137.9951796401"><time>2017-05-29T01:23:24Z</time><ele>615.00</ele></trkpt>
87 * <trkpt lat="35.881072646" lon="137.9951728508"><time>2017-05-29T01:23:27Z</time><ele>615.03</ele></trkpt>
89 static String[][] values = {
90 {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085", null},
91 {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835", "614.90"},
92 {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401", "615.00"},
93 {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508", "615.03"}
96 TagTrkpt createElement(String[] values) throws ParseException {
97 TagTrkpt trkpt = new TagTrkpt(Double.valueOf(values[1]), Double.valueOf(values[2]));
98 trkpt.setTime(ImportPicture.toUTCDate(values[0]));
99 if (values[3] != null) {
100 trkpt.setEle(values[3]);
106 public void setUp() throws Exception {
107 AppParameters params = new AppParameters(AppParameters.FILE_PATH);
108 params.setGpxOverwriteMagvar(true);
110 map = new ElementMapTRKPT(params);
111 for (int cnt = values.length; cnt > 0; cnt--) {
112 map.put(createElement(values[cnt - 1]));
117 public void tearDown() throws Exception {
118 AppParametersTest.delTestData("AdjustTime.ini");
122 public void コンテンツの数をチェック() {
123 assertThat(map.size(), is(4));
127 public void KEYが時間順に取り出せるか() {
129 for (Date key : map.keySet()) {
131 String s = sdf.format(ImportPicture.toUTCDate(values[i++][0]));
132 assertThat(sdf.format(key), is(s));
133 } catch (ParseException e) {
140 public void get_17() throws ParseException {
141 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:17Z"));
142 assertThat(tag, is(nullValue()));
146 public void get_18() throws ParseException {
147 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:18Z"));
148 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
149 assertThat(tag.eleStr, is(nullValue()));
150 assertThat(tag.lat, is(Double.valueOf(values[0][1])));
151 assertThat(tag.lon, is(Double.valueOf(values[0][2])));
152 assertNull(tag.magvarStr);
156 public void get_19() throws ParseException {
157 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:19Z"));
158 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
159 assertNull(tag.eleStr);
160 assertThat(tag.lat, is(Double.valueOf(values[0][1])));
161 assertThat(tag.lon, is(Double.valueOf(values[0][2])));
162 assertNull(tag.magvarStr);
166 public void get_20() throws ParseException {
167 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:20Z"));
168 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
169 assertNull(tag.eleStr);
170 assertThat(tag.lat, is(Double.valueOf(values[0][1])));
171 assertThat(tag.lon, is(Double.valueOf(values[0][2])));
172 assertNull(tag.magvarStr);
176 public void get_21() throws ParseException {
177 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:21Z"));
178 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
179 assertThat(tag.eleStr, is("614.90"));
180 assertThat(tag.lat, is(Double.valueOf(values[1][1])));
181 assertThat(tag.lon, is(Double.valueOf(values[1][2])));
182 assertNotNull(tag.magvarStr);
186 public void get_22() throws ParseException {
187 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:22Z"));
188 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
189 assertThat(tag.eleStr, is("614.90"));
190 assertThat(tag.lat, is(Double.valueOf(values[1][1])));
191 assertThat(tag.lon, is(Double.valueOf(values[1][2])));
192 assertNotNull(tag.magvarStr);
196 public void get_23() throws ParseException {
197 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:23Z"));
198 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
199 assertThat(tag.eleStr, is("614.90"));
200 assertThat(tag.lat, is(Double.valueOf(values[1][1])));
201 assertThat(tag.lon, is(Double.valueOf(values[1][2])));
202 assertNotNull(tag.magvarStr);
206 public void get_24() throws ParseException {
207 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:24Z"));
208 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
209 assertThat(tag.eleStr, is("615.00"));
210 assertThat(tag.lat, is(Double.valueOf(values[2][1])));
211 assertThat(tag.lon, is(Double.valueOf(values[2][2])));
212 assertThat(tag.magvarStr, is(notNullValue()));
216 public void get_25() throws ParseException {
217 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:25Z"));
218 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
219 assertThat(tag.eleStr, is("615.00"));
220 assertThat(tag.lat, is(Double.valueOf(values[2][1])));
221 assertThat(tag.lon, is(Double.valueOf(values[2][2])));
222 assertThat(tag.magvarStr, is(notNullValue()));
226 public void get_26() throws ParseException {
227 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:26Z"));
228 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
229 assertThat(tag.eleStr, is("615.00"));
230 assertThat(tag.lat, is(Double.valueOf(values[2][1])));
231 assertThat(tag.lon, is(Double.valueOf(values[2][2])));
232 assertThat(tag.magvarStr, is(notNullValue()));
236 public void get_27() throws ParseException {
237 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:27Z"));
238 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
239 assertThat(tag.eleStr, is("615.03"));
240 assertThat(tag.lat, is(Double.valueOf(values[3][1])));
241 assertThat(tag.lon, is(Double.valueOf(values[3][2])));
242 assertNotNull(tag.magvarStr);
246 public void get_28() throws ParseException {
247 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:28Z"));
248 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
249 assertThat(tag.eleStr, is("615.03"));
250 assertThat(tag.lat, is(Double.valueOf(values[3][1])));
251 assertThat(tag.lon, is(Double.valueOf(values[3][2])));
252 assertThat(tag.magvarStr, is(notNullValue()));
256 public void get_30() throws ParseException {
257 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:30Z"));
258 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
259 assertThat(tag.eleStr, is("615.03"));
260 assertThat(tag.lat, is(Double.valueOf(values[3][1])));
261 assertThat(tag.lon, is(Double.valueOf(values[3][2])));
262 assertThat(tag.magvarStr, is(notNullValue()));
266 public void get_31() throws ParseException {
267 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:31Z"));
268 assertThat(tag, is(nullValue()));
272 public static class タイムスタンプの書式 {
274 public void EXIF時刻書式テスト() throws Exception {
275 String dateTimeOriginal = "2017:06:30 09:59:59";
276 Date time = ImportPicture.toEXIFDate(dateTimeOriginal);
277 assertThat(ImportPicture.toEXIFString(time), is("2017:06:30 09:59:59"));
278 assertThat(ImportPicture.toUTCString(time), is("2017-06-30T00:59:59Z"));
279 DateFormat dfUTC = new SimpleDateFormat(ImportPicture.TIME_FORMAT_STRING);
280 assertThat(dfUTC.format(time), is("2017-06-30T09:59:59Z"));