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 |
|
---|
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 | }
|
---|