source: josm/trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java@ 10409

Last change on this file since 10409 was 10222, checked in by Don-vip, 8 years ago

findbugs - fix/suppress most of warnings reported in unit tests + enable low confidence warnings for core

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6
7import java.io.File;
8import java.io.IOException;
9import java.text.DecimalFormat;
10import java.text.ParseException;
11import java.text.SimpleDateFormat;
12import java.util.Calendar;
13import java.util.Date;
14import java.util.GregorianCalendar;
15import java.util.TimeZone;
16
17import org.junit.Before;
18import org.junit.Test;
19import org.openstreetmap.josm.TestUtils;
20import org.openstreetmap.josm.data.coor.LatLon;
21import org.openstreetmap.josm.tools.date.DateUtilsTest;
22
23/**
24 * EXIF metadata extraction test
25 * @since 6209
26 */
27public class ExifReaderTest {
28
29 private File orientationSampleFile, directionSampleFile;
30
31 /**
32 * Setup test
33 */
34 @Before
35 public void setUp() {
36 directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
37 orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
38 DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
39 }
40
41 /**
42 * Test time extraction
43 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
44 */
45 @Test
46 public void testReadTime() throws ParseException {
47 Date date = ExifReader.readTime(directionSampleFile);
48 assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
49 }
50
51 /**
52 * Tests reading sub-seconds from the EXIF header
53 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
54 */
55 @Test
56 public void testReadTimeSubSecond1() throws ParseException {
57 Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
58 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
59 assertEquals("2015-07-11T19:34:19.100", dateStr);
60 }
61
62 /**
63 * Test orientation extraction
64 */
65 @Test
66 public void testReadOrientation() {
67 Integer orientation = ExifReader.readOrientation(orientationSampleFile);
68 assertEquals(Integer.valueOf(6), orientation);
69 }
70
71 /**
72 * Test coordinates extraction
73 */
74 @Test
75 public void testReadLatLon() {
76 LatLon latlon = ExifReader.readLatLon(directionSampleFile);
77 assertNotNull(latlon);
78 DecimalFormat f = new DecimalFormat("00.0");
79 assertEquals("51°46'"+f.format(43.0)+"\"", LatLon.dms(latlon.lat()));
80 assertEquals("8°21'"+f.format(56.3)+"\"", LatLon.dms(latlon.lon()));
81 }
82
83 /**
84 * Test direction extraction
85 */
86 @Test
87 public void testReadDirection() {
88 assertEquals(Double.valueOf(46.5), ExifReader.readDirection(directionSampleFile));
89 }
90
91 /**
92 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/11685">#11685</a>
93 * @throws IOException if an error occurs during reading
94 */
95 @Test
96 public void testTicket11685() throws IOException {
97 File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg"));
98 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(ExifReader.readTime(file));
99 assertEquals("2015-11-08T15:33:27.500", dateStr);
100 }
101}
Note: See TracBrowser for help on using the repository browser.