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