1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.advanced;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.BeforeAll;
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.openstreetmap.josm.JOSMFixture;
|
---|
11 | import org.openstreetmap.josm.TestUtils;
|
---|
12 | import org.openstreetmap.josm.spi.preferences.StringSetting;
|
---|
13 |
|
---|
14 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Unit tests of {@link PrefEntry} class.
|
---|
18 | */
|
---|
19 | class PrefEntryTest {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Setup test.
|
---|
23 | */
|
---|
24 | @BeforeAll
|
---|
25 | public static void setUpBeforeClass() {
|
---|
26 | JOSMFixture.createUnitTestFixture().init();
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Unit test of {@link PrefEntry#PrefEntry}.
|
---|
31 | */
|
---|
32 | @Test
|
---|
33 | void testPrefEntry() {
|
---|
34 | String key = "key";
|
---|
35 | StringSetting val = new StringSetting("value");
|
---|
36 | StringSetting def = new StringSetting("defaultValue");
|
---|
37 | PrefEntry pe = new PrefEntry(key, val, def, false);
|
---|
38 | assertFalse(pe.isDefault());
|
---|
39 | assertEquals(key, pe.getKey());
|
---|
40 | assertEquals(val, pe.getValue());
|
---|
41 | assertEquals(def, pe.getDefaultValue());
|
---|
42 | StringSetting val2 = new StringSetting("value2");
|
---|
43 | assertFalse(pe.isChanged());
|
---|
44 | pe.setValue(val2);
|
---|
45 | assertEquals(val2, pe.getValue());
|
---|
46 | assertEquals(val2.toString(), pe.toString());
|
---|
47 | assertTrue(pe.isChanged());
|
---|
48 | pe.reset();
|
---|
49 | pe.markAsChanged();
|
---|
50 | assertTrue(pe.isChanged());
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Unit test of methods {@link PrefEntry#equals} and {@link PrefEntry#hashCode}.
|
---|
55 | */
|
---|
56 | @Test
|
---|
57 | void testEqualsContract() {
|
---|
58 | TestUtils.assumeWorkingEqualsVerifier();
|
---|
59 | EqualsVerifier.forClass(PrefEntry.class).usingGetClass()
|
---|
60 | .withIgnoredFields("value", "defaultValue", "isDefault", "changed")
|
---|
61 | .verify();
|
---|
62 | }
|
---|
63 | }
|
---|