1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.booter;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import junit.framework.TestCase;
27
28
29
30
31 public class PropertiesWrapperTest extends TestCase {
32 public void testAddList() {
33 PropertiesWrapper propertiesWrapper = new PropertiesWrapper(new HashMap<String, String>());
34 List<String> items = new ArrayList<>();
35 items.add("String1");
36 items.add("String2,String3");
37 items.add("String4");
38 items.add("String5,");
39 propertiesWrapper.addList(items, "Test");
40
41 final List test = propertiesWrapper.getStringList("Test");
42 assertEquals(5, test.size());
43 assertEquals("String5", test.get(4));
44 assertEquals("String3", test.get(2));
45 assertEquals("String2", test.get(1));
46 }
47
48 private static final String DUMMY_PREFIX = "dummyPrefix";
49
50 private static final String FIRST_ELEMENT = "foo0";
51
52 private static final String SECOND_ELEMENT = "foo1";
53
54 private final Map<String, String> properties = new HashMap<>();
55
56 private final PropertiesWrapper mapper = new PropertiesWrapper(properties);
57
58 private final Classpath classpathWithTwoElements = createClasspathWithTwoElements();
59
60 public void testReadFromProperties() {
61 properties.put(DUMMY_PREFIX + "0", FIRST_ELEMENT);
62 properties.put(DUMMY_PREFIX + "1", SECOND_ELEMENT);
63 Classpath recreatedClasspath = readClasspathFromProperties();
64 assertEquals(classpathWithTwoElements, recreatedClasspath);
65 }
66
67 public void testReadFromPropertiesWithEmptyProperties() {
68 Classpath recreatedClasspath = readClasspathFromProperties();
69 assertTrue(recreatedClasspath.getClassPath().isEmpty());
70 }
71
72 public void testWriteToProperties() {
73 mapper.setClasspath(DUMMY_PREFIX, classpathWithTwoElements);
74 assertEquals(FIRST_ELEMENT, mapper.getProperty(DUMMY_PREFIX + "0"));
75 assertEquals(SECOND_ELEMENT, mapper.getProperty(DUMMY_PREFIX + "1"));
76 }
77
78 public void testRoundtrip() {
79 mapper.setClasspath(DUMMY_PREFIX, classpathWithTwoElements);
80 Classpath recreatedClasspath = readClasspathFromProperties();
81 assertEquals(classpathWithTwoElements, recreatedClasspath);
82 }
83
84 private Classpath createClasspathWithTwoElements() {
85 return Classpath.emptyClasspath().addClassPathElementUrl(FIRST_ELEMENT).addClassPathElementUrl(SECOND_ELEMENT);
86 }
87
88 private Classpath readClasspathFromProperties() {
89 return mapper.getClasspath(DUMMY_PREFIX);
90 }
91 }