Changeset 10195 in josm


Ignore:
Timestamp:
2016-05-12T05:01:18+02:00 (4 years ago)
Author:
Don-vip
Message:

add more unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/history/HistoryBrowserModelTest.java

    r10108 r10195  
    66import static org.junit.Assert.assertNotNull;
    77import static org.junit.Assert.assertNull;
     8import static org.junit.Assert.assertTrue;
    89
    910import org.junit.BeforeClass;
     
    1213import org.openstreetmap.josm.data.osm.Node;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     15import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    1416import org.openstreetmap.josm.data.osm.User;
    1517import org.openstreetmap.josm.data.osm.history.History;
     
    1719import org.openstreetmap.josm.data.osm.history.HistoryNode;
    1820import org.openstreetmap.josm.gui.history.HistoryBrowserModel.TagTableModel;
     21import org.openstreetmap.josm.gui.history.HistoryBrowserModel.VersionTableModel;
    1922
    2023/**
     
    8992        assertNotEquals(t1, t2);
    9093    }
     94
     95    /**
     96     * Unit test of {@link HistoryBrowserModel#setCurrentPointInTime} and {@link HistoryBrowserModel#setReferencePointInTime} - null history.
     97     */
     98    @Test
     99    public void testSetPointsInTimeNullHistory() {
     100        HistoryBrowserModel model = new HistoryBrowserModel();
     101        VersionTableModel tableModel = model.getVersionTableModel();
     102        tableModel.setValueAt(false, 0, 0); // code coverage
     103        tableModel.setValueAt(true, 0, 1);  // reference point
     104        tableModel.setValueAt(true, 1, 2);  // current point
     105        tableModel.setValueAt(true, 3, 3);  // code coverage
     106    }
     107
     108    /**
     109     * Unit test of {@link HistoryBrowserModel#setCurrentPointInTime} and {@link HistoryBrowserModel#setReferencePointInTime} - node history.
     110     */
     111    @Test
     112    public void testSetPointsInTimeNodeHistory() {
     113        SimplePrimitiveId id = new SimplePrimitiveId(2, OsmPrimitiveType.NODE);
     114        new HistoryLoadTask().add(id).run();
     115        History history = HistoryDataSet.getInstance().getHistory(id);
     116        assertTrue(history.getNumVersions() >= 4);
     117        HistoryBrowserModel model = new HistoryBrowserModel(history);
     118        VersionTableModel tableModel = model.getVersionTableModel();
     119        tableModel.setValueAt(false, 0, 0); // code coverage
     120        tableModel.setValueAt(true, 0, 1);  // reference point
     121        tableModel.setValueAt(true, 3, 2);  // current point
     122        tableModel.setValueAt(true, 3, 3);  // code coverage
     123        // nodes only for ways
     124        assertEquals(0, model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     125        assertEquals(0, model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     126        // members only for relations
     127        assertEquals(0, model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     128        assertEquals(0, model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     129    }
     130
     131    /**
     132     * Unit test of {@link HistoryBrowserModel#setCurrentPointInTime} and {@link HistoryBrowserModel#setReferencePointInTime} - way history.
     133     */
     134    @Test
     135    public void testSetPointsInTimeWayHistory() {
     136        SimplePrimitiveId id = new SimplePrimitiveId(2, OsmPrimitiveType.WAY);
     137        new HistoryLoadTask().add(id).run();
     138        History history = HistoryDataSet.getInstance().getHistory(id);
     139        assertTrue(history.getNumVersions() >= 2);
     140        HistoryBrowserModel model = new HistoryBrowserModel(history);
     141        VersionTableModel tableModel = model.getVersionTableModel();
     142        tableModel.setValueAt(false, 0, 0); // code coverage
     143        tableModel.setValueAt(true, 0, 1);  // reference point
     144        tableModel.setValueAt(true, 3, 2);  // current point
     145        tableModel.setValueAt(true, 3, 3);  // code coverage
     146        // nodes only for ways
     147        assertEquals(2, model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     148        assertEquals(2, model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     149        // members only for relations
     150        assertEquals(0, model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     151        assertEquals(0, model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     152    }
     153
     154    /**
     155     * Unit test of {@link HistoryBrowserModel#setCurrentPointInTime} and {@link HistoryBrowserModel#setReferencePointInTime} - relation history.
     156     */
     157    @Test
     158    public void testSetPointsInTimeRelationHistory() {
     159        SimplePrimitiveId id = new SimplePrimitiveId(2, OsmPrimitiveType.RELATION);
     160        new HistoryLoadTask().add(id).run();
     161        History history = HistoryDataSet.getInstance().getHistory(id);
     162        assertTrue(history.getNumVersions() >= 2);
     163        HistoryBrowserModel model = new HistoryBrowserModel(history);
     164        VersionTableModel tableModel = model.getVersionTableModel();
     165        tableModel.setValueAt(false, 0, 0); // code coverage
     166        tableModel.setValueAt(true, 0, 1);  // reference point
     167        tableModel.setValueAt(true, 3, 2);  // current point
     168        tableModel.setValueAt(true, 3, 3);  // code coverage
     169        // nodes only for ways
     170        assertEquals(0, model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     171        assertEquals(0, model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     172        // members only for relations
     173        assertEquals(1, model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME).getRowCount());
     174        assertEquals(1, model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME).getRowCount());
     175    }
    91176}
Note: See TracChangeset for help on using the changeset viewer.