Changeset 11035 in josm for trunk/test


Ignore:
Timestamp:
2016-09-20T22:46:47+02:00 (3 years ago)
Author:
simon04
Message:

see #13376 - Replace Calendar usages with Java 8 Date API

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java

    r10467 r11035  
    1414import java.nio.file.Files;
    1515import java.nio.file.Paths;
    16 import java.util.Calendar;
     16import java.time.ZoneId;
     17import java.time.ZonedDateTime;
    1718import java.util.Date;
    1819import java.util.List;
     
    8788        Files.createDirectories(task.getAutosaveDir());
    8889        AutosaveLayerInfo info = new AutosaveLayerInfo(new OsmDataLayer(new DataSet(), "layer", null));
    89         Calendar cal = Calendar.getInstance();
    90         cal.set(2016, 0, 1, 1, 2, 3);
    91         cal.set(Calendar.MILLISECOND, 456);
    92         Date fixed = cal.getTime();
     90        Date fixed = Date.from(ZonedDateTime.of(2016, 1, 1, 1, 2, 3, 456_000_000, ZoneId.systemDefault()).toInstant());
    9391
    9492        AutosaveTask.PROP_INDEX_LIMIT.put(5);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java

    r10945 r11035  
    1111
    1212import java.io.StringWriter;
     13import java.time.Instant;
    1314import java.util.Arrays;
    14 import java.util.Calendar;
    1515import java.util.Date;
    16 import java.util.GregorianCalendar;
    1716
    1817import org.junit.After;
     
    2625
    2726import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    28 
    2927/**
    3028 * Unit tests for class {@link DataSetMerger}.
     
    298296    public void testNodeSimpleNoIdSemanticallyEqual() {
    299297
    300         Calendar cal = GregorianCalendar.getInstance();
    301298        User myUser = User.createOsmUser(1111, "my");
    302299
     
    307304        n.put("key1", "value1");
    308305        n.setUser(myUser);
    309         n.setTimestamp(cal.getTime());
     306        n.setTimestamp(new Date());
    310307
    311308        my.addPrimitive(n);
     
    314311        n1.setCoor(LatLon.ZERO);
    315312        n1.put("key1", "value1");
    316         cal.add(Calendar.HOUR, 1);
    317         Date timestamp = cal.getTime();
    318         n1.setTimestamp(timestamp);
     313        n1.setTimestamp(Date.from(Instant.now().plusSeconds(3600)));
    319314        n1.setUser(theirUser);
    320315        their.addPrimitive(n1);
  • trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy

    r10222 r11035  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.io;
    3 
    4 import static org.junit.Assert.*
     2package org.openstreetmap.josm.io
    53
    64import org.junit.Test
     
    86import org.openstreetmap.josm.io.ChangesetQuery.ChangesetQueryUrlParser
    97
     8import java.time.OffsetDateTime
     9import java.time.ZoneOffset
     10
    1011class ChangesetQueryUrlParserTest {
    1112    final shouldFail = new GroovyTestCase().&shouldFail
     
    127128        assert q != null
    128129        assert q.@closedAfter != null
    129         Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
    130         cal.setTime(q.@closedAfter);
    131         assert cal.get(Calendar.YEAR) == 2009
    132         assert cal.get(Calendar.MONTH) == 11 // calendar is 0-based
    133         assert cal.get(Calendar.DAY_OF_MONTH) == 25
    134         assert cal.get(Calendar.HOUR_OF_DAY) == 10
    135         assert cal.get(Calendar.MINUTE) == 0
    136         assert cal.get(Calendar.SECOND) == 0
     130        def cal = q.@closedAfter.toInstant().atOffset(ZoneOffset.UTC)
     131        assert cal == OffsetDateTime.of(2009, 12, 25, 10, 0, 0, 0, ZoneOffset.UTC)
    137132
    138133        // OK
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r10569 r11035  
    1010import java.text.ParseException;
    1111import java.text.SimpleDateFormat;
    12 import java.util.Calendar;
     12import java.time.ZoneId;
     13import java.time.ZonedDateTime;
    1314import java.util.Date;
    14 import java.util.GregorianCalendar;
    1515import java.util.TimeZone;
    1616
     
    2424
    2525import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    26 
    2726/**
    2827 * EXIF metadata extraction test
     
    5554    public void testReadTime() throws ParseException {
    5655        Date date = ExifReader.readTime(directionSampleFile);
    57         assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
     56        assertEquals(ZonedDateTime.of(2010, 5, 15, 17, 12, 5, 0, ZoneId.systemDefault()).toInstant(), date.toInstant());
    5857
    59         TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
     58        final TimeZone zone = TimeZone.getTimeZone("Europe/Berlin");
     59        TimeZone.setDefault(zone);
    6060        date = ExifReader.readTime(directionSampleFile);
    6161        TimeZone.setDefault(DateUtils.UTC);
    62         assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 15, 12, 05).getTime(), date);
     62        assertEquals(ZonedDateTime.of(2010, 5, 15, 17, 12, 5, 0, zone.toZoneId()).toInstant(), date.toInstant());
    6363    }
    6464
Note: See TracChangeset for help on using the changeset viewer.