source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java@ 11115

Last change on this file since 11115 was 11115, checked in by simon04, 8 years ago

fix #13785 - Use streams, add unit tests (patch by alno, modified)

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.junit.Rule;
5import org.junit.Test;
6import org.openstreetmap.josm.testutils.JOSMTestRules;
7
8import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
9import java.util.HashMap;
10import java.util.Map;
11import org.junit.Assert;
12import static org.openstreetmap.josm.data.osm.Changeset.MAX_CHANGESET_TAG_LENGTH;
13
14/**
15 * Unit tests for class {@link Changeset}.
16 */
17public 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
26 /**
27 * Unit test of method {@link Changeset#setKeys}.
28 */
29 @Test
30 public void testSetKeys() {
31 final Changeset cs = new Changeset();
32 // Cannot add null map => IllegalArgumentException
33 try {
34 cs.setKeys(null);
35 Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
36 } catch (IllegalArgumentException e) {
37 // Was expected
38 }
39
40 // Add a map with no values
41 // => the key list is empty
42 Map<String, String> keys = new HashMap<>();
43
44 // Add a map with valid values : null and short texts
45 // => all the items are in the keys
46 keys.put("empty", null);
47 keys.put("test", "test");
48 cs.setKeys(keys);
49 Assert.assertEquals("Both valid keys should have been put in the ChangeSet.", 2, cs.getKeys().size());
50
51 // Add a map with too long values => IllegalArgumentException
52 keys = new HashMap<>();
53 StringBuilder b = new StringBuilder(MAX_CHANGESET_TAG_LENGTH + 1);
54 for (int i = 0; i < MAX_CHANGESET_TAG_LENGTH + 1; i++){
55 b.append("x");
56 }
57 keys.put("test", b.toString());
58 try {
59 cs.setKeys(keys);
60 Assert.fail("Should have thrown an IllegalArgumentException as we gave a too long value.");
61 } catch (IllegalArgumentException e) {
62 // Was expected
63 }
64
65 }
66}
Note: See TracBrowser for help on using the repository browser.