1
1
/*
2
- * Copyright 2002-2007 the original author or authors.
2
+ * Copyright 2002-2009 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import java .util .Properties ;
29
29
import java .util .Set ;
30
30
31
- import junit .framework .TestCase ;
31
+ import static org .junit .Assert .*;
32
+ import org .junit .Test ;
32
33
33
34
/**
34
35
* @author Rob Harrop
35
36
* @author Juergen Hoeller
36
37
* @author Rick Evans
37
38
*/
38
- public class CollectionUtilsTests extends TestCase {
39
+ public class CollectionUtilsTests {
39
40
41
+ @ Test
40
42
public void testIsEmpty () {
41
43
assertTrue (CollectionUtils .isEmpty ((Set ) null ));
42
44
assertTrue (CollectionUtils .isEmpty ((Map ) null ));
@@ -52,6 +54,7 @@ public void testIsEmpty() {
52
54
assertFalse (CollectionUtils .isEmpty (map ));
53
55
}
54
56
57
+ @ Test
55
58
public void testMergeArrayIntoCollection () {
56
59
Object [] arr = new Object [] {"value1" , "value2" };
57
60
List list = new LinkedList ();
@@ -63,6 +66,7 @@ public void testMergeArrayIntoCollection() {
63
66
assertEquals ("value2" , list .get (2 ));
64
67
}
65
68
69
+ @ Test
66
70
public void testMergePrimitiveArrayIntoCollection () {
67
71
int [] arr = new int [] {1 , 2 };
68
72
List list = new LinkedList ();
@@ -74,21 +78,25 @@ public void testMergePrimitiveArrayIntoCollection() {
74
78
assertEquals (new Integer (2 ), list .get (2 ));
75
79
}
76
80
81
+ @ Test
77
82
public void testMergePropertiesIntoMap () {
78
83
Properties defaults = new Properties ();
79
84
defaults .setProperty ("prop1" , "value1" );
80
85
Properties props = new Properties (defaults );
81
86
props .setProperty ("prop2" , "value2" );
87
+ props .put ("prop3" , new Integer (3 ));
82
88
83
89
Map map = new HashMap ();
84
- map .put ("prop3 " , "value3 " );
90
+ map .put ("prop4 " , "value4 " );
85
91
86
92
CollectionUtils .mergePropertiesIntoMap (props , map );
87
93
assertEquals ("value1" , map .get ("prop1" ));
88
94
assertEquals ("value2" , map .get ("prop2" ));
89
- assertEquals ("value3" , map .get ("prop3" ));
95
+ assertEquals (new Integer (3 ), map .get ("prop3" ));
96
+ assertEquals ("value4" , map .get ("prop4" ));
90
97
}
91
98
99
+ @ Test
92
100
public void testContains () {
93
101
assertFalse (CollectionUtils .contains ((Iterator ) null , "myElement" ));
94
102
assertFalse (CollectionUtils .contains ((Enumeration ) null , "myElement" ));
@@ -104,6 +112,7 @@ public void testContains() {
104
112
assertTrue (CollectionUtils .contains (ht .keys (), "myElement" ));
105
113
}
106
114
115
+ @ Test
107
116
public void testContainsAny () throws Exception {
108
117
List source = new ArrayList ();
109
118
source .add ("abc" );
@@ -122,18 +131,21 @@ public void testContainsAny() throws Exception {
122
131
assertFalse (CollectionUtils .containsAny (source , candidates ));
123
132
}
124
133
134
+ @ Test
125
135
public void testContainsInstanceWithNullCollection () throws Exception {
126
136
assertFalse ("Must return false if supplied Collection argument is null" ,
127
137
CollectionUtils .containsInstance (null , this ));
128
138
}
129
139
140
+ @ Test
130
141
public void testContainsInstanceWithInstancesThatAreEqualButDistinct () throws Exception {
131
142
List list = new ArrayList ();
132
143
list .add (new Instance ("fiona" ));
133
144
assertFalse ("Must return false if instance is not in the supplied Collection argument" ,
134
145
CollectionUtils .containsInstance (list , new Instance ("fiona" )));
135
146
}
136
147
148
+ @ Test
137
149
public void testContainsInstanceWithSameInstance () throws Exception {
138
150
List list = new ArrayList ();
139
151
list .add (new Instance ("apple" ));
@@ -143,6 +155,7 @@ public void testContainsInstanceWithSameInstance() throws Exception {
143
155
CollectionUtils .containsInstance (list , instance ));
144
156
}
145
157
158
+ @ Test
146
159
public void testContainsInstanceWithNullInstance () throws Exception {
147
160
List list = new ArrayList ();
148
161
list .add (new Instance ("apple" ));
@@ -151,6 +164,7 @@ public void testContainsInstanceWithNullInstance() throws Exception {
151
164
CollectionUtils .containsInstance (list , null ));
152
165
}
153
166
167
+ @ Test
154
168
public void testFindFirstMatch () throws Exception {
155
169
List source = new ArrayList ();
156
170
source .add ("abc" );
@@ -165,6 +179,7 @@ public void testFindFirstMatch() throws Exception {
165
179
assertEquals ("def" , CollectionUtils .findFirstMatch (source , candidates ));
166
180
}
167
181
182
+ @ Test
168
183
public void testHasUniqueObject () {
169
184
List list = new LinkedList ();
170
185
list .add ("myElement" );
0 commit comments