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.List;
24 import java.util.Properties;
25
26 import junit.framework.TestCase;
27
28
29
30
31 public class PropertiesWrapperTest
32 extends TestCase
33 {
34 public void testAddList()
35 throws Exception
36 {
37
38 Properties props = new Properties();
39 PropertiesWrapper propertiesWrapper = new PropertiesWrapper( props );
40 List items = new ArrayList();
41 items.add( "String1" );
42 items.add( "String2,String3" );
43 items.add( "String4" );
44 items.add( "String5," );
45 propertiesWrapper.addList( items, "Test" );
46
47 final List test = propertiesWrapper.getStringList( "Test" );
48 assertEquals( 5, test.size() );
49 assertEquals( "String5", test.get( 4 ) );
50 assertEquals( "String3", test.get( 2 ) );
51 assertEquals( "String2", test.get( 1 ) );
52
53 }
54
55 private static final String DUMMY_PREFIX = "dummyPrefix";
56
57 private static final String FIRST_ELEMENT = "foo0";
58
59 private static final String SECOND_ELEMENT = "foo1";
60
61 private final Properties properties = new Properties();
62
63
64 private final PropertiesWrapper mapper = new PropertiesWrapper( properties );
65 private final Classpath classpathWithTwoElements = createClasspathWithTwoElements();
66
67 public void testReadFromProperties()
68 throws Exception
69 {
70 properties.put( DUMMY_PREFIX + "0", FIRST_ELEMENT );
71 properties.put( DUMMY_PREFIX + "1", SECOND_ELEMENT );
72 Classpath recreatedClasspath = readClasspathFromProperties();
73 assertEquals( classpathWithTwoElements, recreatedClasspath );
74 }
75
76 public void testReadFromPropertiesWithEmptyProperties()
77 throws Exception
78 {
79 Classpath recreatedClasspath = readClasspathFromProperties();
80 assertTrue( recreatedClasspath.getClassPath().isEmpty() );
81 }
82
83 public void testWriteToProperties()
84 throws Exception
85 {
86 mapper.setClasspath( DUMMY_PREFIX, classpathWithTwoElements);
87 assertEquals( FIRST_ELEMENT, mapper.getProperty( DUMMY_PREFIX + "0" ) );
88 assertEquals( SECOND_ELEMENT, mapper.getProperty( DUMMY_PREFIX + "1" ) );
89 }
90
91 public void testRoundtrip()
92 throws Exception
93 {
94 mapper.setClasspath( DUMMY_PREFIX, classpathWithTwoElements);
95 Classpath recreatedClasspath = readClasspathFromProperties();
96 assertEquals( classpathWithTwoElements, recreatedClasspath );
97 }
98
99 private Classpath createClasspathWithTwoElements()
100 {
101 Classpath classpath = new Classpath();
102 classpath.addClassPathElementUrl( FIRST_ELEMENT );
103 classpath.addClassPathElementUrl( SECOND_ELEMENT );
104 return classpath;
105 }
106
107 private Classpath readClasspathFromProperties()
108 {
109 return mapper.getClasspath( DUMMY_PREFIX);
110 }
111 }