Ignore:
Timestamp:
2021-04-08T22:56:06+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate GPX to Instant

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

Legend:

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

    r17310 r17715  
    88
    99import java.io.File;
     10import java.time.Instant;
    1011import java.util.ArrayList;
    1112import java.util.Arrays;
    1213import java.util.Collections;
    13 import java.util.Date;
    1414import java.util.List;
    1515
     
    2828class ImageDataTest {
    2929
    30     private static ImageEntry newImageEntry(String file, Date exifTime) {
     30    private static ImageEntry newImageEntry(String file, Instant exifTime) {
    3131        ImageEntry entry = new ImageEntry(new File(file));
    3232        entry.setExifTime(exifTime);
     
    6565    @Test
    6666    void testSortData() {
    67         ImageEntry entry1 = newImageEntry("test1", new Date(1_000_000));
    68         ImageEntry entry2 = newImageEntry("test2", new Date(2_000_000));
     67        ImageEntry entry1 = newImageEntry("test1", Instant.ofEpochMilli(1_000_000));
     68        ImageEntry entry2 = newImageEntry("test2", Instant.ofEpochMilli(2_000_000));
    6969
    7070        ArrayList<ImageEntry> list = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r17275 r17715  
    1010
    1111import java.io.IOException;
     12import java.time.Instant;
    1213import java.util.ArrayList;
    1314import java.util.Arrays;
     
    337338        WayPoint p4 = new WayPoint(LatLon.NORTH_POLE);
    338339        WayPoint p5 = new WayPoint(LatLon.NORTH_POLE);
    339         p1.setTime(new Date(200020));
    340         p2.setTime(new Date(100020));
    341         p4.setTime(new Date(500020));
     340        p1.setInstant(new Date(200020).toInstant());
     341        p2.setInstant(new Date(100020).toInstant());
     342        p4.setInstant(new Date(500020).toInstant());
    342343        data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap()));
    343344        data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap()));
    344345
    345         Date[] times = data.getMinMaxTimeForAllTracks();
     346        Instant[] times = data.getMinMaxTimeForAllTracks();
    346347        assertEquals(times.length, 2);
    347         assertEquals(new Date(100020), times[0]);
    348         assertEquals(new Date(500020), times[1]);
     348        assertEquals(Instant.ofEpochMilli(100020), times[0]);
     349        assertEquals(Instant.ofEpochMilli(500020), times[1]);
    349350    }
    350351
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java

    r17275 r17715  
    5858
    5959        final GpxImageEntry ib = new GpxImageEntry();
    60         ib.setExifTime(DateUtils.fromString("2016:01:03 11:54:58")); // 5 minutes before start of GPX
     60        ib.setExifTime(DateUtils.parseInstant("2016:01:03 11:54:58")); // 5 minutes before start of GPX
    6161        ib.createTmp();
    6262        final GpxImageEntry i0 = new GpxImageEntry();
    63         i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
     63        i0.setExifTime(DateUtils.parseInstant("2016:01:03 11:59:54")); // 4 sec before start of GPX
    6464        i0.createTmp();
    6565        final GpxImageEntry i1 = new GpxImageEntry();
    66         i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
     66        i1.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:01"));
    6767        i1.createTmp();
    6868        final GpxImageEntry i2 = new GpxImageEntry();
    69         i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
     69        i2.setExifTime(DateUtils.parseInstant("2016:01:03 12:04:57"));
    7070        i2.createTmp();
    7171        final GpxImageEntry i3 = new GpxImageEntry();
    72         i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
     72        i3.setExifTime(DateUtils.parseInstant("2016:01:03 12:05:05"));
    7373        i3.createTmp();
    7474        final GpxImageEntry i4 = new GpxImageEntry(); //Image close to two points with elevation, but without time
    75         i4.setExifTime(DateUtils.fromString("2016:01:03 12:05:20"));
     75        i4.setExifTime(DateUtils.parseInstant("2016:01:03 12:05:20"));
    7676        i4.createTmp();
    7777        final GpxImageEntry i5 = new GpxImageEntry(); //between two tracks, closer to first
    78         i5.setExifTime(DateUtils.fromString("2016:01:03 12:07:00"));
     78        i5.setExifTime(DateUtils.parseInstant("2016:01:03 12:07:00"));
    7979        i5.createTmp();
    8080        final GpxImageEntry i6 = new GpxImageEntry(); //between two tracks, closer to second (more than 1 minute from any track)
    81         i6.setExifTime(DateUtils.fromString("2016:01:03 12:07:45"));
     81        i6.setExifTime(DateUtils.parseInstant("2016:01:03 12:07:45"));
    8282        i6.createTmp();
    8383
     
    119119        assertEquals(null, i6.getElevation());
    120120
    121         assertEquals(null, ib.getGpsTime());
    122         assertEquals(DateUtils.fromString("2016:01:03 11:59:54"), i0.getGpsTime()); // original time is kept
    123         assertEquals(DateUtils.fromString("2016:01:03 12:04:01"), i1.getGpsTime());
    124         assertEquals(DateUtils.fromString("2016:01:03 12:04:57"), i2.getGpsTime());
    125         assertEquals(DateUtils.fromString("2016:01:03 12:05:05"), i3.getGpsTime());
     121        assertEquals(null, ib.getGpsInstant());
     122        assertEquals(DateUtils.parseInstant("2016:01:03 11:59:54"), i0.getGpsInstant()); // original time is kept
     123        assertEquals(DateUtils.parseInstant("2016:01:03 12:04:01"), i1.getGpsInstant());
     124        assertEquals(DateUtils.parseInstant("2016:01:03 12:04:57"), i2.getGpsInstant());
     125        assertEquals(DateUtils.parseInstant("2016:01:03 12:05:05"), i3.getGpsInstant());
    126126
    127127        clearTmp(images);
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/WayPointTest.java

    r17275 r17715  
    55import org.junit.jupiter.api.Test;
    66import org.openstreetmap.josm.TestUtils;
     7import org.openstreetmap.josm.data.coor.LatLon;
    78import org.openstreetmap.josm.testutils.JOSMTestRules;
    89
     
    1011import nl.jqno.equalsverifier.EqualsVerifier;
    1112import nl.jqno.equalsverifier.Warning;
     13
     14import java.time.Instant;
     15
     16import static org.junit.jupiter.api.Assertions.assertEquals;
     17import static org.junit.jupiter.api.Assertions.assertNotEquals;
    1218
    1319/**
     
    3743            .verify();
    3844    }
     45
     46    /**
     47     * Unit test of copy constructor {@link WayPoint#WayPoint(WayPoint)}
     48     */
     49    @Test
     50    void testConstructor() {
     51        WayPoint wp1 = new WayPoint(new LatLon(12., 34.));
     52        wp1.setInstant(Instant.ofEpochMilli(123_456_789));
     53        WayPoint wp2 = new WayPoint(wp1);
     54        assertEquals(wp1, wp2);
     55        assertEquals(wp1.getInstant(), wp2.getInstant());
     56        wp2.setInstant(Instant.ofEpochMilli(234_456_789));
     57        assertNotEquals(wp1, wp2);
     58        assertNotEquals(wp1.getInstant(), wp2.getInstant());
     59    }
    3960}
Note: See TracChangeset for help on using the changeset viewer.