1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertSame;
|
---|
6 |
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.junit.Before;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.JOSMFixture;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
---|
13 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * JUnit Test of "Name mismatch" validation test.
|
---|
17 | */
|
---|
18 | public class NameMismatchTest {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Setup test.
|
---|
22 | */
|
---|
23 | @Before
|
---|
24 | public void setUp() {
|
---|
25 | JOSMFixture.createUnitTestFixture().init();
|
---|
26 | }
|
---|
27 |
|
---|
28 | List<TestError> test(String primitive) {
|
---|
29 | final NameMismatch test = new NameMismatch();
|
---|
30 | test.check(OsmUtils.createPrimitive(primitive));
|
---|
31 | return test.getErrors();
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test "A name is missing, even though name:* exists."
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | public void test0() {
|
---|
39 | final List<TestError> errors = test("node name:de=Europa");
|
---|
40 | assertSame(1, errors.size());
|
---|
41 | assertEquals("A name is missing, even though name:* exists.", errors.get(0).getMessage());
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Test "Missing name:*={0}. Add tag with correct language key."
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void test1() {
|
---|
49 | final List<TestError> errors = test("node name=Europe name:de=Europa");
|
---|
50 | assertSame(1, errors.size());
|
---|
51 | assertEquals("Missing name:*=Europe. Add tag with correct language key.", errors.get(0).getDescription());
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Test no error
|
---|
56 | */
|
---|
57 | @Test
|
---|
58 | public void test2() {
|
---|
59 | final List<TestError> errors = test("node name=Europe name:de=Europa name:en=Europe");
|
---|
60 | assertSame(0, errors.size());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Various other tests
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | public void test3() {
|
---|
68 | List<TestError> errors;
|
---|
69 | errors = test("node \"name\"=\"Italia - Italien - Italy\"");
|
---|
70 | assertSame(0, errors.size());
|
---|
71 | errors = test("node name=\"Italia - Italien - Italy\" name:it=Italia");
|
---|
72 | assertSame(2, errors.size());
|
---|
73 | errors = test("node name=\"Italia - Italien - Italy\" name:it=Italia name:de=Italien");
|
---|
74 | assertSame(1, errors.size());
|
---|
75 | assertEquals("Missing name:*=Italy. Add tag with correct language key.", errors.get(0).getDescription());
|
---|
76 | errors = test("node name=\"Italia - Italien - Italy\" name:it=Italia name:de=Italien name:en=Italy");
|
---|
77 | assertSame(0, errors.size());
|
---|
78 | }
|
---|
79 | }
|
---|