source: josm/trunk/test/unit/org/openstreetmap/josm/gui/history/HistoryLoadTaskTest.java@ 10108

Last change on this file since 10108 was 10006, checked in by Don-vip, 8 years ago

fix #12639 - NPE in History Window for primitives with more than 100 versions

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.IOException;
7import java.io.InputStream;
8
9import org.junit.BeforeClass;
10import org.junit.Test;
11import org.openstreetmap.josm.JOSMFixture;
12import org.openstreetmap.josm.TestUtils;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.data.osm.Relation;
16import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.data.osm.history.History;
19import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
20import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
21import org.openstreetmap.josm.gui.progress.ProgressMonitor;
22import org.openstreetmap.josm.io.OsmHistoryReader;
23import org.openstreetmap.josm.io.OsmServerHistoryReader;
24import org.openstreetmap.josm.io.OsmTransferException;
25import org.xml.sax.SAXException;
26
27/**
28 * Unit tests of {@link HistoryLoadTask} class.
29 */
30public class HistoryLoadTaskTest {
31
32 /**
33 * Setup test.
34 */
35 @BeforeClass
36 public static void setUpBeforeClass() {
37 JOSMFixture.createUnitTestFixture().init();
38 }
39
40 /**
41 * Unit test of {@link HistoryLoadTask#getLoadingMessage}
42 */
43 @Test
44 public void testGetLoadingMessage() {
45 assertEquals("Loading history for node {0}", HistoryLoadTask.getLoadingMessage(new Node().getPrimitiveId()));
46 assertEquals("Loading history for way {0}", HistoryLoadTask.getLoadingMessage(new Way().getPrimitiveId()));
47 assertEquals("Loading history for relation {0}", HistoryLoadTask.getLoadingMessage(new Relation().getPrimitiveId()));
48
49 assertEquals("", HistoryLoadTask.getLoadingMessage(new SimplePrimitiveId(1, OsmPrimitiveType.CLOSEDWAY)));
50 assertEquals("", HistoryLoadTask.getLoadingMessage(new SimplePrimitiveId(1, OsmPrimitiveType.MULTIPOLYGON)));
51 }
52
53 /**
54 * Unit test of {@link HistoryLoadTask#loadHistory}
55 * @throws OsmTransferException if an error occurs
56 */
57 @Test
58 public void testLoadHistory() throws OsmTransferException {
59 HistoryDataSet ds = HistoryLoadTask.loadHistory(new OsmServerHistoryReader(OsmPrimitiveType.NODE, 0) {
60 @Override
61 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException {
62 try (InputStream in = TestUtils.getRegressionDataStream(12639, "history.xml")) {
63 return new OsmHistoryReader(in).parse(NullProgressMonitor.INSTANCE);
64 } catch (IOException | SAXException e) {
65 throw new OsmTransferException(e);
66 }
67 }
68 }, NullProgressMonitor.INSTANCE);
69 assertEquals(113, ds.getChangesetIds().size());
70 History h = ds.getHistory(1350901, OsmPrimitiveType.RELATION);
71 assertEquals(115, h.getNumVersions());
72 }
73}
Note: See TracBrowser for help on using the repository browser.