1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.validator;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
8 |
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.Arrays;
|
---|
11 | import java.util.Collections;
|
---|
12 | import java.util.Enumeration;
|
---|
13 | import java.util.HashSet;
|
---|
14 | import java.util.Set;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.data.osm.Node;
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
18 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
19 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
20 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
21 |
|
---|
22 | import org.junit.jupiter.api.Test;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit tests of {@link ValidatorTreePanel} class.
|
---|
26 | */
|
---|
27 | @BasicPreferences
|
---|
28 | class ValidatorTreePanelTest {
|
---|
29 | /**
|
---|
30 | * Unit test of {@link ValidatorTreePanel#ValidatorTreePanel}.
|
---|
31 | */
|
---|
32 | @Test
|
---|
33 | void testValidatorTreePanel() {
|
---|
34 | assertDoesNotThrow(() -> new ValidatorTreePanel());
|
---|
35 |
|
---|
36 | ValidatorTreePanel vtp = new ValidatorTreePanel(new ArrayList<>(Arrays.asList(
|
---|
37 | TestError.builder(null, Severity.ERROR, 0)
|
---|
38 | .message("err")
|
---|
39 | .primitives(new Node(1))
|
---|
40 | .build(),
|
---|
41 | TestError.builder(null, Severity.WARNING, 0)
|
---|
42 | .message("warn", "foo")
|
---|
43 | .primitives(new Node(2))
|
---|
44 | .build(),
|
---|
45 | TestError.builder(null, Severity.WARNING, 0)
|
---|
46 | .message("warn", "bar")
|
---|
47 | .primitives(new Node(2))
|
---|
48 | .build())));
|
---|
49 | assertNotNull(vtp);
|
---|
50 | final Enumeration<?> nodes = vtp.getRoot().breadthFirstEnumeration();
|
---|
51 | assertEquals("", nodes.nextElement().toString());
|
---|
52 | assertEquals("Errors (1)", nodes.nextElement().toString());
|
---|
53 | assertEquals("Warnings (2)", nodes.nextElement().toString());
|
---|
54 | assertEquals("err (1)", nodes.nextElement().toString());
|
---|
55 | assertEquals("warn (2)", nodes.nextElement().toString());
|
---|
56 | nodes.nextElement();
|
---|
57 | assertEquals("bar (1)", nodes.nextElement().toString());
|
---|
58 | assertEquals("foo (1)", nodes.nextElement().toString());
|
---|
59 | vtp.setVisible(true);
|
---|
60 | vtp.setVisible(false);
|
---|
61 | Node n = new Node(10);
|
---|
62 | vtp.setErrors(Collections.singletonList(TestError.builder(null, Severity.ERROR, 0)
|
---|
63 | .message("")
|
---|
64 | .primitives(n)
|
---|
65 | .build()));
|
---|
66 | assertEquals(1, vtp.getErrors().size());
|
---|
67 | vtp.selectRelatedErrors(Collections.singleton(n));
|
---|
68 | vtp.expandAll();
|
---|
69 | assertNotNull(vtp.getRoot());
|
---|
70 | vtp.resetErrors();
|
---|
71 | Set<? extends OsmPrimitive> filter = new HashSet<>(Collections.singletonList(n));
|
---|
72 | vtp.setFilter(filter);
|
---|
73 | assertEquals(filter, vtp.getFilter());
|
---|
74 | vtp.setFilter(new HashSet<>());
|
---|
75 | assertNull(vtp.getFilter());
|
---|
76 | vtp.setFilter(null);
|
---|
77 | assertNull(vtp.getFilter());
|
---|
78 | vtp.destroy();
|
---|
79 | }
|
---|
80 | }
|
---|