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

Last change on this file since 7134 was 6246, checked in by Don-vip, 11 years ago

Sonar/FindBugs - various bugfixes / violation fixes

File size: 2.0 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;
13
14import org.junit.Before;
15import org.junit.Test;
16import org.openstreetmap.josm.data.coor.LatLon;
17
18/**
19 * EXIF metadata extraction test
20 * @since 6209
21 */
22public class ExifReaderTest {
23
24 private File sampleFile;
25
26 /**
27 * Setup test
28 * @throws Exception
29 */
30 @Before
31 public void setUp() throws Exception {
32 sampleFile = new File("data_nodist/exif-direction-example.jpg");
33 }
34
35 /**
36 * Test time extraction
37 * @throws ParseException
38 */
39 @Test
40 public void testReadTime() throws ParseException {
41 Date date = ExifReader.readTime(sampleFile);
42 assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
43 }
44
45 /**
46 * Test orientation extraction
47 */
48 @Test
49 public void testReadOrientation() {
50 Integer orientation = ExifReader.readOrientation(sampleFile);
51 assertEquals(Integer.valueOf(1), orientation);
52 }
53
54 /**
55 * Test coordinates extraction
56 */
57 @Test
58 public void testReadLatLon() {
59 LatLon latlon = ExifReader.readLatLon(sampleFile);
60 assertNotNull(latlon);
61 DecimalFormat f = new DecimalFormat("00.0");
62 assertEquals("51°46'"+f.format(43.0)+"\"", LatLon.dms(latlon.lat()));
63 assertEquals("8°21'"+f.format(56.3)+"\"", LatLon.dms(latlon.lon()));
64 }
65
66 /**
67 * Test coordinates extraction
68 */
69 @Test
70 public void testReadDirection() {
71 Double direction = ExifReader.readDirection(sampleFile);
72 assertEquals(new Double(46.5), direction);
73 }
74}
Note: See TracBrowser for help on using the repository browser.