Skip to content

Commit d8fd82a

Browse files
Added more types to test for TypesTest
1 parent 9ea0ed3 commit d8fd82a

3 files changed

Lines changed: 135 additions & 31 deletions

File tree

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/working/RecursiveWorkingCopier.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import java.util.Collection;
2222
import java.util.HashMap;
2323
import java.util.Hashtable;
24+
import java.util.IdentityHashMap;
2425
import java.util.LinkedHashMap;
2526
import java.util.Objects;
27+
import java.util.TreeMap;
28+
import java.util.TreeSet;
2629

2730
import org.slf4j.Logger;
2831
import org.slf4j.LoggerFactory;
@@ -295,6 +298,9 @@ private boolean isSpecialCaseWhereOnlyAFullCopyWorks(final Object valueOfSourceO
295298
valueOfSourceObject.getClass().isAssignableFrom(HashMap.class)
296299
|| valueOfSourceObject.getClass().isAssignableFrom(LinkedHashMap.class)
297300
|| valueOfSourceObject.getClass().isAssignableFrom(Hashtable.class)
301+
|| valueOfSourceObject.getClass().isAssignableFrom(TreeSet.class)
302+
|| valueOfSourceObject.getClass().isAssignableFrom(TreeMap.class)
303+
|| valueOfSourceObject.getClass().isAssignableFrom(IdentityHashMap.class)
298304
);
299305
}
300306

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesData.java

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@
2828
import java.util.HashMap;
2929
import java.util.HashSet;
3030
import java.util.Hashtable;
31+
import java.util.IdentityHashMap;
3132
import java.util.LinkedHashMap;
3233
import java.util.LinkedHashSet;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Optional;
3637
import java.util.Set;
38+
import java.util.Stack;
39+
import java.util.TreeMap;
40+
import java.util.TreeSet;
3741
import java.util.Vector;
42+
import java.util.WeakHashMap;
3843
import java.util.function.Consumer;
3944
import java.util.function.Function;
4045
import java.util.stream.Stream;
@@ -46,7 +51,7 @@
4651

4752
public final class TypesData
4853
{
49-
public record ListOfTestArguments(List<TestArguments> testArguments)
54+
public record ListOfTestArguments(List<TestArguments<?>> testArguments)
5055
{
5156
public Stream<Arguments> toArguments()
5257
{
@@ -55,7 +60,7 @@ public Stream<Arguments> toArguments()
5560
}
5661

5762

58-
public record TestArguments<T extends ComplexObject>(
63+
public record TestArguments<T extends ComplexObject<?>>(
5964
Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
6065
Function<Integer, T> objectCreator,
6166
Consumer<T> objectChanger)
@@ -68,8 +73,9 @@ public Arguments toArguments()
6873

6974
public static Stream<Arguments> generateData()
7075
{
76+
// noinspection RedundantTypeArguments (explicit type arguments speedup compilation and analysis time)
7177
return new ListOfTestArguments(
72-
List.of(
78+
List.<TestArguments<?>>of(
7379
new TestArguments<>(
7480
SetRepository.class,
7581
id -> new SetDaoObject(id, Set.of()),
@@ -100,6 +106,21 @@ public static Stream<Arguments> generateData()
100106
id -> new SetDaoObject(id, new HashSet<>(List.of("1", "2"))),
101107
set -> set.getValue().add("3")
102108
),
109+
new TestArguments<>(
110+
SetRepository.class,
111+
id -> new SetDaoObject(id, new TreeSet<>()),
112+
set -> set.getValue().add("1")
113+
),
114+
new TestArguments<>(
115+
SetRepository.class,
116+
id -> new SetDaoObject(id, new TreeSet<>(List.of("1"))),
117+
set -> set.getValue().add("2")
118+
),
119+
new TestArguments<>(
120+
SetRepository.class,
121+
id -> new SetDaoObject(id, new TreeSet<>(List.of("1", "2"))),
122+
set -> set.getValue().add("3")
123+
),
103124
new TestArguments<>(
104125
SetRepository.class,
105126
id -> new SetDaoObject(id, new LinkedHashSet<>()),
@@ -118,12 +139,12 @@ public static Stream<Arguments> generateData()
118139
new TestArguments<>(
119140
BigDecimalRepository.class,
120141
id -> new BigDecimalDaoObject(id, BigDecimal.ONE),
121-
object -> object.getValue().add(BigDecimal.ONE)
142+
object -> object.setValue(object.getValue().add(BigDecimal.ONE))
122143
),
123144
new TestArguments<>(
124145
BigDecimalRepository.class,
125146
id -> new BigDecimalDaoObject(id, BigDecimal.ZERO),
126-
object -> object.getValue().add(BigDecimal.ONE)
147+
object -> object.setValue(object.getValue().add(BigDecimal.ONE))
127148
),
128149
new TestArguments<>(
129150
BigDecimalRepository.class,
@@ -133,12 +154,12 @@ public static Stream<Arguments> generateData()
133154
new TestArguments<>(
134155
BigIntegerRepository.class,
135156
id -> new BigIntegerDaoObject(id, BigInteger.ONE),
136-
object -> object.getValue().add(BigInteger.ONE)
157+
object -> object.setValue(object.getValue().add(BigInteger.ONE))
137158
),
138159
new TestArguments<>(
139160
BigIntegerRepository.class,
140161
id -> new BigIntegerDaoObject(id, BigInteger.ZERO),
141-
object -> object.getValue().add(BigInteger.ONE)
162+
object -> object.setValue(object.getValue().add(BigInteger.ONE))
142163
),
143164
new TestArguments<>(
144165
BigIntegerRepository.class,
@@ -195,6 +216,32 @@ public static Stream<Arguments> generateData()
195216
id -> new ListDaoObject(id, new ArrayList<>(Set.of("1", "2"))),
196217
object -> object.getValue().add("3")
197218
),
219+
new TestArguments<>(
220+
ListRepository.class,
221+
id -> new ListDaoObject(id, new Stack<>()),
222+
object -> object.getValue().add("1")
223+
),
224+
new TestArguments<>(
225+
ListRepository.class,
226+
id ->
227+
{
228+
final Stack<String> stack = new Stack<>();
229+
stack.add("1");
230+
return new ListDaoObject(id, stack);
231+
},
232+
object -> object.getValue().add("2")
233+
),
234+
new TestArguments<>(
235+
ListRepository.class,
236+
id ->
237+
{
238+
final Stack<String> stack = new Stack<>();
239+
stack.push("1");
240+
stack.push("2");
241+
return new ListDaoObject(id, stack);
242+
},
243+
object -> object.getValue().add("3")
244+
),
198245
new TestArguments<>(
199246
ListRepository.class,
200247
id -> new ListDaoObject(id, new ArrayList<>(Set.of("1"))),
@@ -213,17 +260,17 @@ public static Stream<Arguments> generateData()
213260
new TestArguments<>(
214261
LocalDateRepository.class,
215262
id -> new LocalDateDaoObject(id, LocalDate.of(2000, 1, 1)),
216-
object -> object.getValue().plusDays(1)
263+
object -> object.setValue(object.getValue().plusDays(1))
217264
),
218265
new TestArguments<>(
219266
LocalDateTimeRepository.class,
220267
id -> new LocalDateTimeDaoObject(id, LocalDateTime.of(2000, 1, 1, 1, 1, 1)),
221-
object -> object.getValue().plusDays(1)
268+
object -> object.setValue(object.getValue().plusDays(1))
222269
),
223270
new TestArguments<>(
224271
LocalTimeRepository.class,
225272
id -> new LocalTimeDaoObject(id, LocalTime.of(1, 1, 1)),
226-
object -> object.getValue().plusHours(1)
273+
object -> object.setValue(object.getValue().plusHours(1))
227274
),
228275
new TestArguments<>(
229276
MapRepository.class,
@@ -285,6 +332,36 @@ public static Stream<Arguments> generateData()
285332
id -> new MapDaoObject(id, new Hashtable<>(Map.of("1", "1", "2", "2"))),
286333
set -> set.getValue().put("3", "3")
287334
),
335+
new TestArguments<>(
336+
MapRepository.class,
337+
id -> new MapDaoObject(id, new TreeMap<>()),
338+
set -> set.getValue().put("1", "1")
339+
),
340+
new TestArguments<>(
341+
MapRepository.class,
342+
id -> new MapDaoObject(id, new TreeMap<>(Map.of("1", "1"))),
343+
set -> set.getValue().put("2", "2")
344+
),
345+
new TestArguments<>(
346+
MapRepository.class,
347+
id -> new MapDaoObject(id, new TreeMap<>(Map.of("1", "1", "2", "2"))),
348+
set -> set.getValue().put("3", "3")
349+
),
350+
new TestArguments<>(
351+
MapRepository.class,
352+
id -> new MapDaoObject(id, new IdentityHashMap<>()),
353+
set -> set.getValue().put("1", "1")
354+
),
355+
new TestArguments<>(
356+
MapRepository.class,
357+
id -> new MapDaoObject(id, new IdentityHashMap<>(Map.of("1", "1"))),
358+
set -> set.getValue().put("2", "2")
359+
),
360+
new TestArguments<>(
361+
MapRepository.class,
362+
id -> new MapDaoObject(id, new IdentityHashMap<>(Map.of("1", "1", "2", "2"))),
363+
set -> set.getValue().put("3", "3")
364+
),
288365
new TestArguments<>(
289366
OptionalRepository.class,
290367
id -> new OptionalDaoObject(id, Optional.of("1")),
@@ -334,6 +411,21 @@ public static Stream<Arguments> generateNotWorkingData()
334411
id -> new EnumMapDaoObject(id, new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1"))),
335412
object -> object.getValue().remove(EnumMapDaoObject.Album.RUMOURS)
336413
),
414+
new TestArguments<>(
415+
MapRepository.class,
416+
id -> new MapDaoObject(id, new WeakHashMap<>()),
417+
set -> set.getValue().put("1", "1")
418+
),
419+
new TestArguments<>(
420+
MapRepository.class,
421+
id -> new MapDaoObject(id, new WeakHashMap<>(Map.of("1", "1"))),
422+
set -> set.getValue().put("2", "2")
423+
),
424+
new TestArguments<>(
425+
MapRepository.class,
426+
id -> new MapDaoObject(id, new WeakHashMap<>(Map.of("1", "1", "2", "2"))),
427+
set -> set.getValue().put("3", "3")
428+
),
337429
// Here EclipseStore has problems: https://github.com/microstream-one/microstream/issues/173
338430
new TestArguments<>(
339431
CalendarRepository.class,

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesTest.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.special.types;
1717

18-
import java.util.List;
18+
import java.util.Collection;
19+
import java.util.Map;
1920
import java.util.Optional;
2021
import java.util.function.Consumer;
2122
import java.util.function.Function;
@@ -64,11 +65,7 @@ <T extends ComplexObject<?>> void simpleStoreAndRead(
6465

6566
TestUtil.doBeforeAndAfterRestartOfDatastore(
6667
this.storage,
67-
() -> {
68-
final List<T> storedObjects = TestUtil.iterableToList(repository.findAll());
69-
Assertions.assertEquals(1, storedObjects.size());
70-
Assertions.assertEquals(objectToStore, storedObjects.get(0));
71-
}
68+
() -> this.dynamicAssertEquals(1, repository, objectToStore)
7269
);
7370
}
7471

@@ -116,11 +113,7 @@ <T extends ComplexObject<?>> void simpleChangeAfterStore(
116113

117114
TestUtil.doBeforeAndAfterRestartOfDatastore(
118115
this.storage,
119-
() -> {
120-
final Optional<T> storedObject2 = repository.findById(1);
121-
Assertions.assertTrue(storedObject2.isPresent());
122-
Assertions.assertEquals(storedObject, storedObject2);
123-
}
116+
() -> this.dynamicAssertEquals(1, repository, storedObject.get())
124117
);
125118
}
126119

@@ -141,11 +134,7 @@ <T extends ComplexObject<?>> void doubleStoreSameEntityWithChange(
141134

142135
TestUtil.doBeforeAndAfterRestartOfDatastore(
143136
this.storage,
144-
() -> {
145-
final Optional<T> storedObject = repository.findById(1);
146-
Assertions.assertTrue(storedObject.isPresent());
147-
Assertions.assertEquals(objectToStore, storedObject.get());
148-
}
137+
() -> this.dynamicAssertEquals(1, repository, objectToStore)
149138
);
150139
}
151140

@@ -164,11 +153,28 @@ <T extends ComplexObject<?>> void simpleChangeBeforeStore(
164153

165154
TestUtil.doBeforeAndAfterRestartOfDatastore(
166155
this.storage,
167-
() -> {
168-
final Optional<T> storedObject2 = repository.findById(1);
169-
Assertions.assertTrue(storedObject2.isPresent());
170-
Assertions.assertEquals(objectToStore, storedObject2.get());
171-
}
156+
() -> this.dynamicAssertEquals(1, repository, objectToStore)
172157
);
173158
}
159+
160+
private <T extends ComplexObject<?>> void dynamicAssertEquals(
161+
final int id,
162+
final EclipseStoreRepository<T, Integer> repository,
163+
final T objectToStore)
164+
{
165+
final Optional<T> storedObject2 = repository.findById(id);
166+
Assertions.assertTrue(storedObject2.isPresent());
167+
if(storedObject2.get().getValue() instanceof final Map<?, ?> storedMap)
168+
{
169+
Assertions.assertEquals(((Map<?, ?>)objectToStore.getValue()).size(), storedMap.size());
170+
}
171+
else if(storedObject2.get().getValue() instanceof final Collection<?> storedList)
172+
{
173+
Assertions.assertEquals(((Collection<?>)objectToStore.getValue()).size(), storedList.size());
174+
}
175+
else
176+
{
177+
Assertions.assertEquals(objectToStore, storedObject2.get());
178+
}
179+
}
174180
}

0 commit comments

Comments
 (0)