# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Users\alexandre.nouvel\Documents\NetBeansProjects\trunk\test\unit
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: org/openstreetmap/josm/data/osm/ChangesetCacheTest.java
--- org/openstreetmap/josm/data/osm/ChangesetCacheTest.java No Base Revision
+++ org/openstreetmap/josm/data/osm/ChangesetCacheTest.java Locally New
@@ -0,0 +1,58 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.Assert;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Unit tests for class {@link ChangesetCache}.
+ */
+public class ChangesetCacheTest {
+
+    /**
+     * Setup test.
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+    public ChangesetCache cache;
+    
+    /**
+     * Unit test of method {@link ChangesetCache#getOpenChangesets}.
+     */
+    @Test
+    public void testGetOpenChangesets() {
+        cache = ChangesetCache.getInstance();
+        // empty cache => empty list
+        Assert.assertTrue(
+            "Empty cache should produce an empty list.",
+            cache.getOpenChangesets().isEmpty()
+        );
+        
+        // cache with only closed changesets => empty list
+        Changeset closedCs = new Changeset(1);
+        closedCs.setOpen(false);
+        cache.update(closedCs);
+        Assert.assertTrue(
+            "Cache with only closed changesets should produce an empty list.",
+            cache.getOpenChangesets().isEmpty()
+        );
+        
+        // cache with open and closed changesets => list with only the open ones
+        Changeset openCs = new Changeset(2);
+        openCs.setOpen(true);
+        cache.update(openCs);
+        List<Changeset> expected = new ArrayList();
+        expected.add(openCs);
+        Assert.assertEquals(
+            expected,
+            cache.getOpenChangesets()
+        );
+    }
+}
Index: org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java
--- org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java No Base Revision
+++ org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java Locally New
@@ -0,0 +1,65 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.Assert;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Date;
+import java.util.Set;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.history.HistoryNode;
+import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
+
+/**
+ * Unit tests for class {@link ChangesetDataSet}.
+ */
+public class ChangesetDataSetTest {
+
+    /**
+     * Setup test.
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+    public ChangesetDataSet cds;
+    
+    /**
+     * Unit test of method {@link ChangesetDataSet#getPrimitivesByModificationType}.
+     */
+    @Test
+    public void testGetPrimitivesByModificationType() {
+        cds = new ChangesetDataSet();
+        // empty object, null parameter => IllegalArgumentException
+        try {
+            cds.getPrimitivesByModificationType(null);
+            Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
+        } catch (IllegalArgumentException e) {
+            // Was expected
+        }
+        
+        // empty object, a modification type => empty list
+        Assert.assertTrue(
+            "Empty data set should produce an empty list.",
+            cds.getPrimitivesByModificationType(
+                    ChangesetModificationType.CREATED).isEmpty()
+        );
+        
+        // object with various items and modification types, fetch for CREATED
+        // => list containing only the CREATED item
+        HistoryOsmPrimitive prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
+        HistoryOsmPrimitive prim2 = new HistoryNode(2, 1, true, User.createLocalUser("test"), 1, new Date(), LatLon.NORTH_POLE);
+        HistoryOsmPrimitive prim3 = new HistoryNode(3, 1, true, User.getAnonymous(), 1, new Date(), LatLon.SOUTH_POLE);
+        cds.put(prim1, ChangesetModificationType.CREATED);
+        cds.put(prim2, ChangesetModificationType.DELETED);
+        cds.put(prim3, ChangesetModificationType.UPDATED);
+        Set<HistoryOsmPrimitive> result = cds.getPrimitivesByModificationType(
+                    ChangesetModificationType.CREATED);
+        Assert.assertEquals("We should have found only one item.", 1, result.size());
+        Assert.assertTrue("The item found is prim1.", result.contains(prim1));
+        
+    }
+}
Index: org/openstreetmap/josm/data/osm/ChangesetTest.java
--- org/openstreetmap/josm/data/osm/ChangesetTest.java No Base Revision
+++ org/openstreetmap/josm/data/osm/ChangesetTest.java Locally New
@@ -0,0 +1,67 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Assert;
+import static org.openstreetmap.josm.data.osm.Changeset.MAX_CHANGESET_TAG_LENGTH;
+
+/**
+ * Unit tests for class {@link Changeset}.
+ */
+public class ChangesetTest {
+
+    /**
+     * Setup test.
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+    public Changeset cs;
+    
+    /**
+     * Unit test of method {@link ChangeSet#setKeys}.
+     */
+    @Test
+    public void testSetKeys() {
+        cs = new Changeset();
+        // Cannot add null map => IllegalArgumentException
+        try {
+            cs.setKeys(null);
+            Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
+        } catch (IllegalArgumentException e) {
+            // Was expected
+        }
+        
+        // Add a map with no values
+        // => the key list is empty
+        Map<String, String> keys = new HashMap<>();
+        
+        // Add a map with valid values : null and short texts
+        // => all the items are in the keys
+        keys.put("empty", null);
+        keys.put("test", "test");
+        cs.setKeys(keys);
+        Assert.assertEquals("Both valid keys should have been put in the ChangeSet.", 2, cs.getKeys().size());
+        
+        // Add a map with too long values => IllegalArgumentException
+        keys = new HashMap<>();
+        StringBuilder b = new StringBuilder(MAX_CHANGESET_TAG_LENGTH + 1);
+        for (int i = 0; i < MAX_CHANGESET_TAG_LENGTH + 1; i++){
+           b.append("x");
+        }
+        keys.put("test", b.toString());
+        try {
+            cs.setKeys(keys);
+            Assert.fail("Should have thrown an IllegalArgumentException as we gave a too long value.");
+        } catch (IllegalArgumentException e) {
+            // Was expected
+        }
+                
+    }
+}
Index: org/openstreetmap/josm/data/osm/DataSetTest.java
--- org/openstreetmap/josm/data/osm/DataSetTest.java No Base Revision
+++ org/openstreetmap/josm/data/osm/DataSetTest.java Locally New
@@ -0,0 +1,63 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.Assert;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.history.HistoryNode;
+import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
+
+/**
+ * Unit tests for class {@link DataSet}.
+ */
+public class DataSetTest {
+
+    /**
+     * Setup test.
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+    public DataSet ds;
+    
+    /**
+     * Unit test of method {@link DataSet#searchRelations}.
+     */
+    @Test
+    public void testSearchRelations() {
+        ds = new DataSet();
+        // null bbox => empty list
+        Assert.assertTrue(
+            "Empty data set should produce an empty list.",
+            ds.searchRelations(null).isEmpty()
+        );
+        
+        // empty data set, any bbox => empty list
+        BBox bbox = new BBox(LatLon.NORTH_POLE, LatLon.SOUTH_POLE);
+        Assert.assertTrue(
+            "Empty data set should produce an empty list.",
+            ds.searchRelations(bbox).isEmpty()
+        );
+        
+        // data set with elements in the given bbox => these elements
+        Node node = new Node(LatLon.ZERO);
+        Relation r = new Relation(1);
+        RelationMember rm = new RelationMember("role", node);
+        r.addMember(rm);
+        ds.addPrimitive(node);
+        ds.addPrimitive(r);
+        bbox = new BBox(new LatLon(-1.0, -1.0), new LatLon(1.0, 1.0));
+        List<Relation> result = ds.searchRelations(bbox);
+        Assert.assertEquals("We should have found only one item.", 1, result.size());
+        Assert.assertTrue("The item found is relation r.", result.contains(r));
+        
+    }
+}
Index: org/openstreetmap/josm/tools/CheckParameterUtilTest.java
--- org/openstreetmap/josm/tools/CheckParameterUtilTest.java No Base Revision
+++ org/openstreetmap/josm/tools/CheckParameterUtilTest.java Locally New
@@ -0,0 +1,43 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.tools;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import org.junit.Assert;
+import org.openstreetmap.josm.data.osm.Changeset;
+
+/**
+ * Unit tests for class {@link ChangeSet}.
+ */
+public class CheckParameterUtilTest {
+
+    /**
+     * Setup test.
+     */
+    @Rule
+    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+    public JOSMTestRules test = new JOSMTestRules();
+    public Changeset cs;
+    
+    /**
+     * Unit test of method {@link CheckParameterUtil#ensureParameterNotNull}.
+     */
+    @Test
+    public void testEnsureParameterNotNull()
+    throws IllegalArgumentException {
+        // Use a null parameter => IllegalArgumentException
+        try {
+            CheckParameterUtil.ensureParameterNotNull(null, "param");
+            Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
+        } catch (IllegalArgumentException e) {
+            // Was expected
+        }
+        
+        // Anything not null => no exception
+        CheckParameterUtil.ensureParameterNotNull("anything", "param");
+
+    }
+}
