Skip to content

Commit 4d62198

Browse files
committed
add more types
1 parent a09ef5d commit 4d62198

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

src/main/java/it/aboutbits/springboot/testing/validation/source/SizeGreaterThanValueSource.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
import java.util.Collection;
99
import java.util.HashMap;
1010
import java.util.HashSet;
11+
import java.util.LinkedHashMap;
12+
import java.util.LinkedHashSet;
1113
import java.util.LinkedList;
1214
import java.util.List;
1315
import java.util.Map;
1416
import java.util.Random;
1517
import java.util.Set;
1618
import java.util.TreeMap;
1719
import java.util.TreeSet;
20+
import java.util.concurrent.ConcurrentHashMap;
21+
import java.util.concurrent.ConcurrentMap;
1822
import java.util.function.LongFunction;
1923
import java.util.stream.Stream;
2024

@@ -31,10 +35,14 @@ public class SizeGreaterThanValueSource implements ValueSource {
3135
TYPE_SOURCES.put(LinkedList.class, SizeGreaterThanValueSource::getLinkedListStream);
3236
TYPE_SOURCES.put(Set.class, SizeGreaterThanValueSource::getHashSetStream);
3337
TYPE_SOURCES.put(HashSet.class, SizeGreaterThanValueSource::getHashSetStream);
38+
TYPE_SOURCES.put(LinkedHashSet.class, SizeGreaterThanValueSource::getLinkedHashSetStream);
3439
TYPE_SOURCES.put(TreeSet.class, SizeGreaterThanValueSource::getTreeSetStream);
3540
TYPE_SOURCES.put(Map.class, SizeGreaterThanValueSource::getHashMapStream);
3641
TYPE_SOURCES.put(HashMap.class, SizeGreaterThanValueSource::getHashMapStream);
42+
TYPE_SOURCES.put(LinkedHashMap.class, SizeGreaterThanValueSource::getLinkedHashMapStream);
3743
TYPE_SOURCES.put(TreeMap.class, SizeGreaterThanValueSource::getTreeMapStream);
44+
TYPE_SOURCES.put(ConcurrentMap.class, SizeGreaterThanValueSource::getConcurrentHashMapStream);
45+
TYPE_SOURCES.put(ConcurrentHashMap.class, SizeGreaterThanValueSource::getConcurrentHashMapStream);
3846
}
3947

4048
@SuppressWarnings("unused")
@@ -87,6 +95,16 @@ private static Stream<Collection<?>> getHashSetStream(long value) {
8795
));
8896
}
8997

98+
@NonNull
99+
private static Stream<Collection<?>> getLinkedHashSetStream(long value) {
100+
return getTestSizes(value)
101+
.stream()
102+
.map(size -> generateCollection(
103+
Math.toIntExact(size),
104+
new LinkedHashSet<>()
105+
));
106+
}
107+
90108
@NonNull
91109
private static Stream<Collection<?>> getTreeSetStream(long value) {
92110
return getTestSizes(value)
@@ -127,6 +145,16 @@ private static Stream<Collection<?>> getLinkedListStream(long value) {
127145
));
128146
}
129147

148+
@NonNull
149+
private static Stream<Map<?, ?>> getLinkedHashMapStream(long value) {
150+
return getTestSizes(value)
151+
.stream()
152+
.map(size -> generateMap(
153+
Math.toIntExact(size),
154+
new LinkedHashMap<>()
155+
));
156+
}
157+
130158
@NonNull
131159
private static Stream<Map<?, ?>> getTreeMapStream(long value) {
132160
return getTestSizes(value)
@@ -137,6 +165,16 @@ private static Stream<Collection<?>> getLinkedListStream(long value) {
137165
));
138166
}
139167

168+
@NonNull
169+
private static Stream<Map<?, ?>> getConcurrentHashMapStream(long value) {
170+
return getTestSizes(value)
171+
.stream()
172+
.map(size -> generateMap(
173+
Math.toIntExact(size),
174+
new ConcurrentHashMap<>()
175+
));
176+
}
177+
140178
private static List<Long> getTestSizes(long value) {
141179
var sizes = new ArrayList<Long>();
142180

src/main/java/it/aboutbits/springboot/testing/validation/source/SizeLessThanValueSource.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
import java.util.Collection;
99
import java.util.HashMap;
1010
import java.util.HashSet;
11+
import java.util.LinkedHashMap;
12+
import java.util.LinkedHashSet;
1113
import java.util.LinkedList;
1214
import java.util.List;
1315
import java.util.Map;
1416
import java.util.Random;
1517
import java.util.Set;
1618
import java.util.TreeMap;
1719
import java.util.TreeSet;
20+
import java.util.concurrent.ConcurrentHashMap;
21+
import java.util.concurrent.ConcurrentMap;
1822
import java.util.function.LongFunction;
1923
import java.util.stream.Stream;
2024

@@ -31,10 +35,14 @@ public class SizeLessThanValueSource implements ValueSource {
3135
TYPE_SOURCES.put(LinkedList.class, SizeLessThanValueSource::getLinkedListStream);
3236
TYPE_SOURCES.put(Set.class, SizeLessThanValueSource::getHashSetStream);
3337
TYPE_SOURCES.put(HashSet.class, SizeLessThanValueSource::getHashSetStream);
38+
TYPE_SOURCES.put(LinkedHashSet.class, SizeLessThanValueSource::getLinkedHashSetStream);
3439
TYPE_SOURCES.put(TreeSet.class, SizeLessThanValueSource::getTreeSetStream);
3540
TYPE_SOURCES.put(Map.class, SizeLessThanValueSource::getHashMapStream);
3641
TYPE_SOURCES.put(HashMap.class, SizeLessThanValueSource::getHashMapStream);
42+
TYPE_SOURCES.put(LinkedHashMap.class, SizeLessThanValueSource::getLinkedHashMapStream);
3743
TYPE_SOURCES.put(TreeMap.class, SizeLessThanValueSource::getTreeMapStream);
44+
TYPE_SOURCES.put(ConcurrentMap.class, SizeLessThanValueSource::getConcurrentHashMapStream);
45+
TYPE_SOURCES.put(ConcurrentHashMap.class, SizeLessThanValueSource::getConcurrentHashMapStream);
3846
}
3947

4048
@SuppressWarnings("unused")
@@ -123,6 +131,18 @@ private static Stream<Collection<?>> getHashSetStream(long value) {
123131
);
124132
}
125133

134+
@NonNull
135+
private static Stream<Collection<?>> getLinkedHashSetStream(long value) {
136+
return Stream.concat(
137+
Stream.of(new LinkedHashSet<>()),
138+
Stream.iterate(1L, i -> i < value, i -> i + 1)
139+
.map(size -> generateCollection(
140+
Math.toIntExact(size),
141+
new LinkedHashSet<>()
142+
))
143+
);
144+
}
145+
126146
@NonNull
127147
private static Stream<Collection<?>> getTreeSetStream(long value) {
128148
return Stream.concat(
@@ -147,6 +167,18 @@ private static Stream<Collection<?>> getTreeSetStream(long value) {
147167
);
148168
}
149169

170+
@NonNull
171+
private static Stream<Map<?, ?>> getLinkedHashMapStream(long value) {
172+
return Stream.concat(
173+
Stream.of(new LinkedHashMap<>()),
174+
Stream.iterate(1L, i -> i < value, i -> i + 1)
175+
.map(size -> generateMap(
176+
Math.toIntExact(size),
177+
new LinkedHashMap<>()
178+
))
179+
);
180+
}
181+
150182
@NonNull
151183
private static Stream<Map<?, ?>> getTreeMapStream(long value) {
152184
return Stream.concat(
@@ -159,6 +191,18 @@ private static Stream<Collection<?>> getTreeSetStream(long value) {
159191
);
160192
}
161193

194+
@NonNull
195+
private static Stream<Map<?, ?>> getConcurrentHashMapStream(long value) {
196+
return Stream.concat(
197+
Stream.of(new ConcurrentHashMap<>()),
198+
Stream.iterate(1L, i -> i < value, i -> i + 1)
199+
.map(size -> generateMap(
200+
Math.toIntExact(size),
201+
new ConcurrentHashMap<>()
202+
))
203+
);
204+
}
205+
162206
private static String generateRandomString(int length) {
163207
// Include printable ASCII characters (32-126) which includes space and common characters
164208
return RANDOM.ints(length, 32, 127)

0 commit comments

Comments
 (0)