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