Ticket #13045: patch-test-fix-timezone.patch

File patch-test-fix-timezone.patch, 8.8 KB (added by michael2402, 9 years ago)
  • src/org/openstreetmap/josm/io/NmeaReader.java

    diff --git a/src/org/openstreetmap/josm/io/NmeaReader.java b/src/org/openstreetmap/josm/io/NmeaReader.java
    index 62179e6..a803059 100644
    a b import org.openstreetmap.josm.data.gpx.GpxConstants;  
    1919import org.openstreetmap.josm.data.gpx.GpxData;
    2020import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    2121import org.openstreetmap.josm.data.gpx.WayPoint;
     22import org.openstreetmap.josm.tools.date.DateUtils;
    2223
    2324/**
    2425 * Reads a NMEA file. Based on information from
    public class NmeaReader {  
    165166    }
    166167
    167168    public NmeaReader(InputStream source) throws IOException {
     169        rmcTimeFmt.setTimeZone(DateUtils.UTC);
     170        rmcTimeFmtStd.setTimeZone(DateUtils.UTC);
    168171
    169172        // create the data tree
    170173        data = new GpxData();
  • src/org/openstreetmap/josm/tools/date/DateUtils.java

    diff --git a/src/org/openstreetmap/josm/tools/date/DateUtils.java b/src/org/openstreetmap/josm/tools/date/DateUtils.java
    index b956925..3cbb811 100644
    a b import org.openstreetmap.josm.tools.UncheckedParseException;  
    2929 */
    3030public final class DateUtils {
    3131
     32    /**
     33     * The UTC time zone.
     34     */
     35    public static final TimeZone UTC = TimeZone.getTimeZone("UTC");
     36
    3237    protected DateUtils() {
    3338        // Hide default constructor for utils classes
    3439    }
    public final class DateUtils {  
    4550     * The shared instance is used because the construction, together
    4651     * with the timezone lookup, is very expensive.
    4752     */
    48     private static final GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
     53    private static final GregorianCalendar calendar = new GregorianCalendar(UTC);
    4954    private static final GregorianCalendar calendarLocale = new GregorianCalendar(TimeZone.getDefault());
    5055    private static final DatatypeFactory XML_DATE;
    5156
  • test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java

    diff --git a/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java b/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java
    index 88f6ad7..b3172ef 100644
    a b import java.util.ArrayList;  
    99import java.util.List;
    1010import java.util.TimeZone;
    1111
     12import org.junit.Rule;
    1213import org.junit.Test;
    1314import org.openstreetmap.josm.data.coor.LatLon;
    1415import org.openstreetmap.josm.data.gpx.GpxConstants;
    1516import org.openstreetmap.josm.data.gpx.WayPoint;
    1617import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
     18import org.openstreetmap.josm.testutils.JOSMTestRules;
    1719
     20import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1821import nl.jqno.equalsverifier.EqualsVerifier;
    1922
    2023/**
    2124 * Unit tests of {@link NmeaReader} class.
    2225 */
    2326public class NmeaReaderTest {
     27    /**
     28     * Set the timezone and timeout.
     29     */
     30    @Rule
     31    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     32    public JOSMTestRules test = new JOSMTestRules();
    2433
    2534    /**
    2635     * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}.
    public class NmeaReaderTest {  
    3645     */
    3746    @Test
    3847    public void testReader() throws Exception {
     48        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    3949        final NmeaReader in = new NmeaReader(new FileInputStream("data_nodist/btnmeatrack_2016-01-25.nmea"));
    4050        assertEquals(30, in.getNumberOfCoordinates());
    4151        assertEquals(0, in.getParserMalformed());
    4252
    43         TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    4453        final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
    45         assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
    46         assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
    47         assertEquals("2016-01-25T04:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME));
     54        assertEquals("2016-01-25T05:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
     55        assertEquals("2016-01-25T05:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
     56        assertEquals("2016-01-25T05:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME));
    4857
    4958        final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    50         assertEquals("2016-01-25T05:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
    51         assertEquals("2016-01-25T05:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
    52         assertEquals("2016-01-25T05:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
     59        assertEquals("2016-01-25T06:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
     60        assertEquals("2016-01-25T06:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
     61        assertEquals("2016-01-25T06:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
    5362
    5463        assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
    5564        assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE));
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index a6033d0..9fba4cd 100644
    a b import org.openstreetmap.josm.io.OsmApi;  
    1919import org.openstreetmap.josm.io.OsmApiInitializationException;
    2020import org.openstreetmap.josm.io.OsmTransferCanceledException;
    2121import org.openstreetmap.josm.tools.I18n;
     22import org.openstreetmap.josm.tools.date.DateUtils;
    2223
    2324import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2425
    public class JOSMTestRules implements TestRule {  
    164165        // Tests are running headless by default.
    165166        System.setProperty("java.awt.headless", "true");
    166167        // All tests use the same timezone.
    167         TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     168        TimeZone.setDefault(DateUtils.UTC);
    168169        // Set log level to info
    169170        Main.logLevel = 3;
    170171
  • test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    diff --git a/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java b/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java
    index ae18936..7ae3e3a 100644
    a b import java.util.Date;  
    1414import java.util.GregorianCalendar;
    1515import java.util.TimeZone;
    1616
     17import org.junit.After;
    1718import org.junit.Before;
     19import org.junit.Rule;
    1820import org.junit.Test;
    1921import org.openstreetmap.josm.TestUtils;
    2022import org.openstreetmap.josm.data.coor.LatLon;
     23import org.openstreetmap.josm.testutils.JOSMTestRules;
     24import org.openstreetmap.josm.tools.date.DateUtils;
    2125import org.openstreetmap.josm.tools.date.DateUtilsTest;
    2226
     27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     28
    2329/**
    2430 * EXIF metadata extraction test
    2531 * @since 6209
    2632 */
    2733public class ExifReaderTest {
     34    /**
     35     * Set the timezone and timeout.
     36     */
     37    @Rule
     38    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     39    public JOSMTestRules test = new JOSMTestRules();
    2840
    2941    private File orientationSampleFile, directionSampleFile;
    3042
    public class ExifReaderTest {  
    3951    }
    4052
    4153    /**
     54     * Clean {@link DateUtils} state
     55     */
     56    @After
     57    public void done() {
     58        DateUtilsTest.setTimeZone(DateUtils.UTC);
     59    }
     60
     61    /**
    4262     * Test time extraction
    4363     * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
    4464     */
    4565    @Test
    4666    public void testReadTime() throws ParseException {
    4767        Date date = ExifReader.readTime(directionSampleFile);
    48         assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
     68        assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 15, 12, 05).getTime(), date);
    4969    }
    5070
    5171    /**
    public class ExifReaderTest {  
    5676    public void testReadTimeSubSecond1() throws ParseException {
    5777        Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
    5878        String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
    59         assertEquals("2015-07-11T19:34:19.100", dateStr);
     79        assertEquals("2015-07-11T17:34:19.100", dateStr);
    6080    }
    6181
    6282    /**
    public class ExifReaderTest {  
    96116    public void testTicket11685() throws IOException {
    97117        File file = new File(TestUtils.getRegressionDataFile(11685, "2015-11-08_15-33-27-Xiaomi_YI-Y0030832.jpg"));
    98118        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);
     119        assertEquals("2015-11-08T14:33:27.500", dateStr);
    100120    }
    101121}