source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanelTest.java

Last change on this file was 18690, checked in by taylor.smock, 14 months ago

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.validator;
3
4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertNotNull;
7import static org.junit.jupiter.api.Assertions.assertNull;
8
9import java.util.ArrayList;
10import java.util.Arrays;
11import java.util.Collections;
12import java.util.Enumeration;
13import java.util.HashSet;
14import java.util.Set;
15
16import org.openstreetmap.josm.data.osm.Node;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.validation.Severity;
19import org.openstreetmap.josm.data.validation.TestError;
20import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
21
22import org.junit.jupiter.api.Test;
23
24/**
25 * Unit tests of {@link ValidatorTreePanel} class.
26 */
27@BasicPreferences
28class 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}
Note: See TracBrowser for help on using the repository browser.