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