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;
11 import javax.xml.parsers.DocumentBuilder;
12 import javax.xml.parsers.DocumentBuilderFactory;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.experimental.runners.Enclosed;
16 import org.junit.runner.RunWith;
17 import org.w3c.dom.DOMImplementation;
18 import org.w3c.dom.Document;
19 import org.w3c.dom.Element;
21 @RunWith(Enclosed.class)
22 public class ElementMapTRKPTTest {
24 public static class Keyのみ {
25 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
26 ElementMapTRKPT map = null;
28 static String[] values = {
29 "1970-01-01 08:59:59.999",
30 "1970-01-01 09:00:00.000",
31 "1970-01-01 09:00:00.001",
32 "2018-10-25 07:59:59.999",
33 "2018-10-25 08:00:00.000",
34 "2018-10-25 08:00:00.001"
38 public void setUp() throws Exception {
39 timeL = (sdf.parse("2018-10-25 08:00:00.000")).getTime();
40 map = new ElementMapTRKPT();
41 map.put(new Date(timeL), null); // 5-6: 2018-10-25 08:00:00.000
42 map.put(new Date(timeL + 1L), null); // 7: 2018-10-25 08:00:00.001
43 map.put(new Date(timeL - 1L), null); // 4: 2018-10-25 07:59:59.999
44 map.put(new Date(1L), null); // 3: 1970-01-01 09:00:00.001
45 map.put(new Date(0L), null); // 2: 1970-01-01 09:00:00.000
46 map.put(new Date(-1L), null); // 1: 1970-01-01 08:59:59.999
47 map.put(new Date(timeL), null); // 5-6: 2018-10-25 08:00:00.000
51 public void 同一キーをPUTした場合() {
52 assertThat(map.size(), is(6));
56 public void イテレータを使って読みだす() {
57 assertThat(map.size(), is(6));
60 for (Date key : map.keySet()) {
61 assertThat(sdf.format(key), is(values[i++]));
66 public void 拡張FOR文を使って読みだす() {
67 assertThat(map.size(), is(6));
70 for (Date key : map.keySet()) {
71 assertThat(sdf.format(key), is(values[i++]));
76 public static class Keyとvalueのセット {
77 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
78 ElementMapTRKPT map = null;
82 * <trkpt lat="35.8812697884" lon="137.9952202085"><time>2017-05-29T01:23:18Z</time></trkpt>
83 * <trkpt lat="35.8811769169" lon="137.9951928835"><time>2017-05-29T01:23:21Z</time><ele>614.90</ele></trkpt>
84 * <trkpt lat="35.881112963" lon="137.9951796401"><time>2017-05-29T01:23:24Z</time><ele>615.00</ele></trkpt>
85 * <trkpt lat="35.881072646" lon="137.9951728508"><time>2017-05-29T01:23:27Z</time><ele>615.03</ele></trkpt>
87 static String[][] values = {
88 {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085", null},
89 {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835", "614.90"},
90 {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401", "615.00"},
91 {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508", "615.03"}
94 Element createElement(Document document, String[] values) {
95 Element trkpt = document.createElement("trkpt");
96 trkpt.setAttribute("lat", values[1]);
97 trkpt.setAttribute("lon", values[2]);
98 Element timeE = document.createElement("time");
99 timeE.appendChild(document.createTextNode(values[0]));
100 trkpt.appendChild(timeE);
101 if (values[3] != null) {
102 Element eleE = document.createElement("ele");
103 eleE.appendChild(document.createTextNode(values[3]));
104 trkpt.appendChild(eleE);
110 public void setUp() throws Exception {
111 Complementation.param_GpxOverwriteMagvar = true;
113 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
114 DocumentBuilder builder = factory.newDocumentBuilder();
115 DOMImplementation domImpl=builder.getDOMImplementation();
116 Document document = domImpl.createDocument("","trkpt",null);
118 map = new ElementMapTRKPT();
119 for (int cnt = 4; cnt > 0; cnt--) {
120 map.put(new TagTrkpt(createElement(document, values[cnt - 1])));
125 public void コンテンツの数をチェック() {
126 assertThat(map.size(), is(4));
130 public void KEYが時間順に取り出せるか() {
132 for (Date key : map.keySet()) {
134 String s = sdf.format(ImportPicture.toUTCDate(values[i++][0]));
135 assertThat(sdf.format(key), is(s));
136 } catch (ParseException e) {
143 public void get_17() throws ParseException {
144 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:17Z"));
145 assertThat(tag, is(nullValue()));
149 public void get_18() throws ParseException {
150 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:18Z"));
151 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
152 assertThat(tag.eleStr, is(nullValue()));
153 assertThat(tag.lat, is(new Double(values[0][1])));
154 assertThat(tag.lon, is(new Double(values[0][2])));
155 assertThat(tag.magvarStr, is(nullValue()));
159 public void get_19() throws ParseException {
160 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:19Z"));
161 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
162 assertThat(tag.eleStr, is(nullValue()));
163 assertThat(tag.lat, is(new Double(values[0][1])));
164 assertThat(tag.lon, is(new Double(values[0][2])));
165 assertThat(tag.magvarStr, is(nullValue()));
169 public void get_20() throws ParseException {
170 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:20Z"));
171 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
172 assertThat(tag.eleStr, is(nullValue()));
173 assertThat(tag.lat, is(new Double(values[0][1])));
174 assertThat(tag.lon, is(new Double(values[0][2])));
175 assertThat(tag.magvarStr, is(nullValue()));
179 public void get_21() throws ParseException {
180 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:21Z"));
181 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
182 assertThat(tag.eleStr, is("614.90"));
183 assertThat(tag.lat, is(new Double(values[1][1])));
184 assertThat(tag.lon, is(new Double(values[1][2])));
185 assertThat(tag.magvarStr, is(notNullValue()));
189 public void get_22() throws ParseException {
190 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:22Z"));
191 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
192 assertThat(tag.eleStr, is("614.90"));
193 assertThat(tag.lat, is(new Double(values[1][1])));
194 assertThat(tag.lon, is(new Double(values[1][2])));
195 assertThat(tag.magvarStr, is(notNullValue()));
199 public void get_23() throws ParseException {
200 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:23Z"));
201 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
202 assertThat(tag.eleStr, is("614.90"));
203 assertThat(tag.lat, is(new Double(values[1][1])));
204 assertThat(tag.lon, is(new Double(values[1][2])));
205 assertThat(tag.magvarStr, is(notNullValue()));
209 public void get_24() throws ParseException {
210 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:24Z"));
211 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
212 assertThat(tag.eleStr, is("615.00"));
213 assertThat(tag.lat, is(new Double(values[2][1])));
214 assertThat(tag.lon, is(new Double(values[2][2])));
215 assertThat(tag.magvarStr, is(notNullValue()));
219 public void get_25() throws ParseException {
220 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:25Z"));
221 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
222 assertThat(tag.eleStr, is("615.00"));
223 assertThat(tag.lat, is(new Double(values[2][1])));
224 assertThat(tag.lon, is(new Double(values[2][2])));
225 assertThat(tag.magvarStr, is(notNullValue()));
229 public void get_26() throws ParseException {
230 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:26Z"));
231 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
232 assertThat(tag.eleStr, is("615.00"));
233 assertThat(tag.lat, is(new Double(values[2][1])));
234 assertThat(tag.lon, is(new Double(values[2][2])));
235 assertThat(tag.magvarStr, is(notNullValue()));
239 public void get_27() throws ParseException {
240 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:27Z"));
241 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
242 assertThat(tag.eleStr, is("615.03"));
243 assertThat(tag.lat, is(new Double(values[3][1])));
244 assertThat(tag.lon, is(new Double(values[3][2])));
245 assertThat(tag.magvarStr, is(notNullValue()));
249 public void get_28() throws ParseException {
250 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:28Z"));
251 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
252 assertThat(tag.eleStr, is("615.03"));
253 assertThat(tag.lat, is(new Double(values[3][1])));
254 assertThat(tag.lon, is(new Double(values[3][2])));
255 assertThat(tag.magvarStr, is(notNullValue()));
259 public void get_30() throws ParseException {
260 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:30Z"));
261 assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
262 assertThat(tag.eleStr, is("615.03"));
263 assertThat(tag.lat, is(new Double(values[3][1])));
264 assertThat(tag.lon, is(new Double(values[3][2])));
265 assertThat(tag.magvarStr, is(notNullValue()));
269 public void get_31() throws ParseException {
270 TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:31Z"));
271 assertThat(tag, is(nullValue()));
275 public static class タイムスタンプの書式 {
277 public void EXIF時刻書式テスト() throws Exception {
278 String dateTimeOriginal = "2017:06:30 09:59:59";
279 Date time = ImportPicture.toEXIFDate(dateTimeOriginal);
280 assertThat(ImportPicture.toEXIFString(time), is("2017:06:30 09:59:59"));
281 assertThat(ImportPicture.toUTCString(time), is("2017-06-30T00:59:59Z"));
282 DateFormat dfUTC = new SimpleDateFormat(ImportPicture.TIME_FORMAT_STRING);
283 assertThat(dfUTC.format(time), is("2017-06-30T09:59:59Z"));