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

Last change on this file since 9394 was 9394, checked in by simon04, 3 years ago

Fix timezone aware unit tests

  • Property svn:eol-style set to native
File size: 2.2 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.text.DecimalFormat;
9import java.text.ParseException;
10import java.util.Calendar;
11import java.util.Date;
12import java.util.GregorianCalendar;
13import java.util.TimeZone;
14
15import org.junit.Before;
16import org.junit.Test;
17import org.openstreetmap.josm.data.coor.LatLon;
18import org.openstreetmap.josm.tools.date.DateUtilsTest;
19
20/**
21 * EXIF metadata extraction test
22 * @since 6209
23 */
24public class ExifReaderTest {
25
26    private File orientationSampleFile, directionSampleFile;
27
28    /**
29     * Setup test
30     */
31    @Before
32    public void setUp() {
33        directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
34        orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
35        DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
36    }
37
38    /**
39     * Test time extraction
40     * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
41     */
42    @Test
43    public void testReadTime() throws ParseException {
44        Date date = ExifReader.readTime(directionSampleFile);
45        assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
46    }
47
48    /**
49     * Test orientation extraction
50     */
51    @Test
52    public void testReadOrientation() {
53        Integer orientation = ExifReader.readOrientation(orientationSampleFile);
54        assertEquals(Integer.valueOf(6), orientation);
55    }
56
57    /**
58     * Test coordinates extraction
59     */
60    @Test
61    public void testReadLatLon() {
62        LatLon latlon = ExifReader.readLatLon(directionSampleFile);
63        assertNotNull(latlon);
64        DecimalFormat f = new DecimalFormat("00.0");
65        assertEquals("51°46'"+f.format(43.0)+"\"", LatLon.dms(latlon.lat()));
66        assertEquals("8°21'"+f.format(56.3)+"\"", LatLon.dms(latlon.lon()));
67    }
68
69    /**
70     * Test coordinates extraction
71     */
72    @Test
73    public void testReadDirection() {
74        Double direction = ExifReader.readDirection(directionSampleFile);
75        assertEquals(new Double(46.5), direction);
76    }
77}
Note: See TracBrowser for help on using the repository browser.