Changeset 9394 in josm


Ignore:
Timestamp:
2016-01-10T18:06:13+01:00 (9 years ago)
Author:
simon04
Message:

Fix timezone aware unit tests

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r9385 r9394  
    303303        return getDateTimeFormat(dateStyle, timeStyle).format(datetime);
    304304    }
     305
     306    /**
     307     * Allows to override the timezone for unit tests.
     308     * @param zone the timezone to use
     309     */
     310    protected static void setTimeZone(TimeZone zone) {
     311        calendarLocale.setTimeZone(zone);
     312    }
    305313}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java

    r9384 r9394  
    1313import org.openstreetmap.josm.io.GpxReaderTest;
    1414import org.openstreetmap.josm.tools.date.DateUtils;
     15import org.openstreetmap.josm.tools.date.DateUtilsTest;
    1516
    1617/**
     
    2425    @BeforeClass
    2526    public static void setUp() {
    26         TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     27        DateUtilsTest.setTimeZone(TimeZone.getTimeZone("UTC"));
    2728    }
    2829
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r8509 r9394  
    1111import java.util.Date;
    1212import java.util.GregorianCalendar;
     13import java.util.TimeZone;
    1314
    1415import org.junit.Before;
    1516import org.junit.Test;
    1617import org.openstreetmap.josm.data.coor.LatLon;
     18import org.openstreetmap.josm.tools.date.DateUtilsTest;
    1719
    1820/**
     
    3133        directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
    3234        orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
     35        DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
    3336    }
    3437
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r9385 r9394  
    44import static org.junit.Assert.assertEquals;
    55
    6 import java.util.Date;
    76import java.util.TimeZone;
    87
     
    1716
    1817    /**
    19      * Setup test.
     18     * Allows to override the timezone used in {@link DateUtils} for unit tests.
     19     * @param zone the timezone to use
    2020     */
    21     @BeforeClass
    22     public static void setUp() {
    23         TimeZone.setDefault(TimeZone.getTimeZone("GMT+8:00"));
     21    public static void setTimeZone(TimeZone zone) {
     22        DateUtils.setTimeZone(zone);
    2423    }
    2524
     
    4544    @Test
    4645    public void testExifDate() {
     46        setTimeZone(TimeZone.getTimeZone("GMT+8:00")); // parsing is timezone aware
    4747        assertEquals(1443038712000L - 8 * 3600 * 1000, DateUtils.fromString("2015:09:23 20:05:12").getTime());
    4848        assertEquals(1443038712888L - 8 * 3600 * 1000, DateUtils.fromString("2015:09:23 20:05:12.888").getTime());
Note: See TracChangeset for help on using the changeset viewer.