Ticket #13785: use-of-streams-unit-tests.patch
File use-of-streams-unit-tests.patch, 11.8 KB (added by , 7 years ago) |
---|
-
org/openstreetmap/josm/data/osm/ChangesetCacheTest.java
# 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.
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm; 3 4 import org.junit.Rule; 5 import org.junit.Test; 6 import org.junit.Assert; 7 import org.openstreetmap.josm.testutils.JOSMTestRules; 8 9 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 10 import java.util.ArrayList; 11 import java.util.List; 12 13 /** 14 * Unit tests for class {@link ChangesetCache}. 15 */ 16 public class ChangesetCacheTest { 17 18 /** 19 * Setup test. 20 */ 21 @Rule 22 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules test = new JOSMTestRules(); 24 public ChangesetCache cache; 25 26 /** 27 * Unit test of method {@link ChangesetCache#getOpenChangesets}. 28 */ 29 @Test 30 public void testGetOpenChangesets() { 31 cache = ChangesetCache.getInstance(); 32 // empty cache => empty list 33 Assert.assertTrue( 34 "Empty cache should produce an empty list.", 35 cache.getOpenChangesets().isEmpty() 36 ); 37 38 // cache with only closed changesets => empty list 39 Changeset closedCs = new Changeset(1); 40 closedCs.setOpen(false); 41 cache.update(closedCs); 42 Assert.assertTrue( 43 "Cache with only closed changesets should produce an empty list.", 44 cache.getOpenChangesets().isEmpty() 45 ); 46 47 // cache with open and closed changesets => list with only the open ones 48 Changeset openCs = new Changeset(2); 49 openCs.setOpen(true); 50 cache.update(openCs); 51 List<Changeset> expected = new ArrayList(); 52 expected.add(openCs); 53 Assert.assertEquals( 54 expected, 55 cache.getOpenChangesets() 56 ); 57 } 58 } -
org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm; 3 4 import org.junit.Rule; 5 import org.junit.Test; 6 import org.junit.Assert; 7 import org.openstreetmap.josm.testutils.JOSMTestRules; 8 import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType; 9 10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 import java.util.Date; 12 import java.util.Set; 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.history.HistoryNode; 15 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 16 17 /** 18 * Unit tests for class {@link ChangesetDataSet}. 19 */ 20 public class ChangesetDataSetTest { 21 22 /** 23 * Setup test. 24 */ 25 @Rule 26 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 27 public JOSMTestRules test = new JOSMTestRules(); 28 public ChangesetDataSet cds; 29 30 /** 31 * Unit test of method {@link ChangesetDataSet#getPrimitivesByModificationType}. 32 */ 33 @Test 34 public void testGetPrimitivesByModificationType() { 35 cds = new ChangesetDataSet(); 36 // empty object, null parameter => IllegalArgumentException 37 try { 38 cds.getPrimitivesByModificationType(null); 39 Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument."); 40 } catch (IllegalArgumentException e) { 41 // Was expected 42 } 43 44 // empty object, a modification type => empty list 45 Assert.assertTrue( 46 "Empty data set should produce an empty list.", 47 cds.getPrimitivesByModificationType( 48 ChangesetModificationType.CREATED).isEmpty() 49 ); 50 51 // object with various items and modification types, fetch for CREATED 52 // => list containing only the CREATED item 53 HistoryOsmPrimitive prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO); 54 HistoryOsmPrimitive prim2 = new HistoryNode(2, 1, true, User.createLocalUser("test"), 1, new Date(), LatLon.NORTH_POLE); 55 HistoryOsmPrimitive prim3 = new HistoryNode(3, 1, true, User.getAnonymous(), 1, new Date(), LatLon.SOUTH_POLE); 56 cds.put(prim1, ChangesetModificationType.CREATED); 57 cds.put(prim2, ChangesetModificationType.DELETED); 58 cds.put(prim3, ChangesetModificationType.UPDATED); 59 Set<HistoryOsmPrimitive> result = cds.getPrimitivesByModificationType( 60 ChangesetModificationType.CREATED); 61 Assert.assertEquals("We should have found only one item.", 1, result.size()); 62 Assert.assertTrue("The item found is prim1.", result.contains(prim1)); 63 64 } 65 } -
org/openstreetmap/josm/data/osm/ChangesetTest.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm; 3 4 import org.junit.Rule; 5 import org.junit.Test; 6 import org.openstreetmap.josm.testutils.JOSMTestRules; 7 8 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 9 import java.util.HashMap; 10 import java.util.Map; 11 import org.junit.Assert; 12 import static org.openstreetmap.josm.data.osm.Changeset.MAX_CHANGESET_TAG_LENGTH; 13 14 /** 15 * Unit tests for class {@link Changeset}. 16 */ 17 public class ChangesetTest { 18 19 /** 20 * Setup test. 21 */ 22 @Rule 23 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 24 public JOSMTestRules test = new JOSMTestRules(); 25 public Changeset cs; 26 27 /** 28 * Unit test of method {@link ChangeSet#setKeys}. 29 */ 30 @Test 31 public void testSetKeys() { 32 cs = new Changeset(); 33 // Cannot add null map => IllegalArgumentException 34 try { 35 cs.setKeys(null); 36 Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument."); 37 } catch (IllegalArgumentException e) { 38 // Was expected 39 } 40 41 // Add a map with no values 42 // => the key list is empty 43 Map<String, String> keys = new HashMap<>(); 44 45 // Add a map with valid values : null and short texts 46 // => all the items are in the keys 47 keys.put("empty", null); 48 keys.put("test", "test"); 49 cs.setKeys(keys); 50 Assert.assertEquals("Both valid keys should have been put in the ChangeSet.", 2, cs.getKeys().size()); 51 52 // Add a map with too long values => IllegalArgumentException 53 keys = new HashMap<>(); 54 StringBuilder b = new StringBuilder(MAX_CHANGESET_TAG_LENGTH + 1); 55 for (int i = 0; i < MAX_CHANGESET_TAG_LENGTH + 1; i++){ 56 b.append("x"); 57 } 58 keys.put("test", b.toString()); 59 try { 60 cs.setKeys(keys); 61 Assert.fail("Should have thrown an IllegalArgumentException as we gave a too long value."); 62 } catch (IllegalArgumentException e) { 63 // Was expected 64 } 65 66 } 67 } -
org/openstreetmap/josm/data/osm/DataSetTest.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm; 3 4 import org.junit.Rule; 5 import org.junit.Test; 6 import org.junit.Assert; 7 import org.openstreetmap.josm.testutils.JOSMTestRules; 8 import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType; 9 10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 import java.util.Date; 12 import java.util.List; 13 import java.util.Set; 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.data.osm.history.HistoryNode; 16 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 17 18 /** 19 * Unit tests for class {@link DataSet}. 20 */ 21 public class DataSetTest { 22 23 /** 24 * Setup test. 25 */ 26 @Rule 27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 28 public JOSMTestRules test = new JOSMTestRules(); 29 public DataSet ds; 30 31 /** 32 * Unit test of method {@link DataSet#searchRelations}. 33 */ 34 @Test 35 public void testSearchRelations() { 36 ds = new DataSet(); 37 // null bbox => empty list 38 Assert.assertTrue( 39 "Empty data set should produce an empty list.", 40 ds.searchRelations(null).isEmpty() 41 ); 42 43 // empty data set, any bbox => empty list 44 BBox bbox = new BBox(LatLon.NORTH_POLE, LatLon.SOUTH_POLE); 45 Assert.assertTrue( 46 "Empty data set should produce an empty list.", 47 ds.searchRelations(bbox).isEmpty() 48 ); 49 50 // data set with elements in the given bbox => these elements 51 Node node = new Node(LatLon.ZERO); 52 Relation r = new Relation(1); 53 RelationMember rm = new RelationMember("role", node); 54 r.addMember(rm); 55 ds.addPrimitive(node); 56 ds.addPrimitive(r); 57 bbox = new BBox(new LatLon(-1.0, -1.0), new LatLon(1.0, 1.0)); 58 List<Relation> result = ds.searchRelations(bbox); 59 Assert.assertEquals("We should have found only one item.", 1, result.size()); 60 Assert.assertTrue("The item found is relation r.", result.contains(r)); 61 62 } 63 } -
org/openstreetmap/josm/tools/CheckParameterUtilTest.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.tools; 3 4 import org.junit.Rule; 5 import org.junit.Test; 6 import org.openstreetmap.josm.testutils.JOSMTestRules; 7 8 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 9 import org.junit.Assert; 10 import org.openstreetmap.josm.data.osm.Changeset; 11 12 /** 13 * Unit tests for class {@link ChangeSet}. 14 */ 15 public class CheckParameterUtilTest { 16 17 /** 18 * Setup test. 19 */ 20 @Rule 21 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 22 public JOSMTestRules test = new JOSMTestRules(); 23 public Changeset cs; 24 25 /** 26 * Unit test of method {@link CheckParameterUtil#ensureParameterNotNull}. 27 */ 28 @Test 29 public void testEnsureParameterNotNull() 30 throws IllegalArgumentException { 31 // Use a null parameter => IllegalArgumentException 32 try { 33 CheckParameterUtil.ensureParameterNotNull(null, "param"); 34 Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument."); 35 } catch (IllegalArgumentException e) { 36 // Was expected 37 } 38 39 // Anything not null => no exception 40 CheckParameterUtil.ensureParameterNotNull("anything", "param"); 41 42 } 43 }