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, 8 years ago

Fix timezone aware unit tests

  • Property svn:eol-style set to native
File size: 2.2 KB
RevLine 
[7937]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;
[9394]13import java.util.TimeZone;
[7937]14
15import org.junit.Before;
16import org.junit.Test;
17import org.openstreetmap.josm.data.coor.LatLon;
[9394]18import org.openstreetmap.josm.tools.date.DateUtilsTest;
[7937]19
20/**
21 * EXIF metadata extraction test
22 * @since 6209
23 */
24public class ExifReaderTest {
25
[7959]26 private File orientationSampleFile, directionSampleFile;
[8509]27
[7937]28 /**
29 * Setup test
30 */
31 @Before
[8509]32 public void setUp() {
[7959]33 directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
34 orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
[9394]35 DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
[7937]36 }
37
[8509]38 /**
[7937]39 * Test time extraction
[8509]40 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
[7937]41 */
42 @Test
43 public void testReadTime() throws ParseException {
[7959]44 Date date = ExifReader.readTime(directionSampleFile);
[7937]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() {
[7959]53 Integer orientation = ExifReader.readOrientation(orientationSampleFile);
54 assertEquals(Integer.valueOf(6), orientation);
[7937]55 }
[8509]56
[7937]57 /**
58 * Test coordinates extraction
59 */
60 @Test
61 public void testReadLatLon() {
[7959]62 LatLon latlon = ExifReader.readLatLon(directionSampleFile);
[7937]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() {
[7959]74 Double direction = ExifReader.readDirection(directionSampleFile);
[7937]75 assertEquals(new Double(46.5), direction);
76 }
77}
Note: See TracBrowser for help on using the repository browser.