Skip to content

Commit 1554388

Browse files
committed
refactor(spring-data-40): simple test refactoring
1 parent 3316a26 commit 1554388

File tree

10 files changed

+43
-52
lines changed

10 files changed

+43
-52
lines changed

tarantool-spring-data/tarantool-spring-data-40/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<spring.boot.version>4.0.4</spring.boot.version>
2424
<shared.dir>${project.parent.parent.basedir}/tarantool-shared-resources/</shared.dir>
2525
<license.header.file>${project.parent.parent.basedir}/LICENSE_HEADER.txt</license.header.file>
26+
<!-- Spring framework 7.x перешел на 6 версию -->
27+
<junit.version>6.0.3</junit.version>
2628
</properties>
2729

2830
<dependencies>

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/config/GenericTarantoolConfigurationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.nio.file.Files;
1010

11+
import org.jspecify.annotations.NonNull;
1112
import org.junit.jupiter.api.AfterAll;
1213
import org.junit.jupiter.api.BeforeAll;
1314
import org.springframework.beans.BeansException;
@@ -30,7 +31,7 @@ public abstract class GenericTarantoolConfigurationTest implements ApplicationCo
3031
@Autowired protected TarantoolProperties properties;
3132

3233
@Override
33-
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
34+
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
3435
this.applicationContext = applicationContext;
3536
}
3637

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/core/annotation/IdClassResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void testResolveIdClassTypeWithEntityWithoutAnnotation() {
3939
@Test
4040
void testResolveIdClassTypeWithEntityWithAnnotation() {
4141
assertEquals(
42-
ID_CLASS_RESOLVER.resolveIdClassType(ComplexPerson.class), CompositePersonKey.class);
42+
CompositePersonKey.class, ID_CLASS_RESOLVER.resolveIdClassType(ComplexPerson.class));
4343
}
4444

4545
@Test

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/core/mapping/KeyValueCompositePropertyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
import static org.junit.jupiter.api.Assertions.assertEquals;
1515
import static org.junit.jupiter.api.Assertions.assertNotNull;
1616
import static org.junit.jupiter.api.Assertions.assertNull;
17+
import org.jspecify.annotations.Nullable;
1718
import org.junit.jupiter.api.BeforeEach;
1819
import org.junit.jupiter.api.Test;
1920
import org.springframework.data.annotation.Id;
21+
import org.springframework.data.core.TypeInformation;
2022
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
2123
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
2224
import org.springframework.data.mapping.PersistentEntity;
2325
import org.springframework.data.mapping.PersistentProperty;
2426
import org.springframework.data.mapping.model.Property;
2527
import org.springframework.data.mapping.model.SimpleTypeHolder;
26-
import org.springframework.data.util.TypeInformation;
27-
import org.springframework.lang.Nullable;
2828
import org.springframework.util.ReflectionUtils;
2929

3030
public class KeyValueCompositePropertyTest<P extends KeyValuePersistentProperty<P>> {

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/core/mapping/TarantoolMappingContextTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1414
import static org.junit.jupiter.api.Assertions.assertNotNull;
1515
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
import org.jspecify.annotations.NonNull;
17+
import org.jspecify.annotations.Nullable;
1618
import org.junit.jupiter.api.Assertions;
1719
import org.junit.jupiter.api.Test;
1820
import org.springframework.core.annotation.AnnotatedElementUtils;
1921
import org.springframework.core.annotation.AnnotationUtils;
2022
import org.springframework.data.annotation.Id;
23+
import org.springframework.data.core.TypeInformation;
2124
import org.springframework.data.keyvalue.annotation.KeySpace;
2225
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
2326
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
2427
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
28+
import org.springframework.data.mapping.MappingException;
2529
import org.springframework.data.mapping.PersistentEntity;
2630
import org.springframework.data.mapping.PersistentProperty;
27-
import org.springframework.data.mapping.context.MappingContext;
2831
import org.springframework.data.mapping.model.Property;
2932
import org.springframework.data.mapping.model.SimpleTypeHolder;
30-
import org.springframework.data.util.TypeInformation;
31-
import org.springframework.lang.Nullable;
3233
import org.springframework.util.Assert;
3334
import org.springframework.util.ClassUtils;
3435
import org.springframework.util.ReflectionUtils;
@@ -85,52 +86,51 @@ void testCreatePersistentProperty() {
8586
@Test
8687
void testCreateEntityWithWrongCompositeKeyPartTypes() {
8788
Set<Class<?>> initialSet =
88-
new HashSet<Class<?>>() {
89+
new HashSet<>() {
8990
{
9091
add(EntityWithWrongFieldTypes.class);
9192
}
9293
};
93-
IllegalArgumentException exception =
94-
assertThrows(IllegalArgumentException.class, () -> initEntities(initialSet));
94+
MappingException exception =
95+
assertThrows(MappingException.class, () -> initEntities(initialSet));
96+
final Throwable cause = exception.getCause();
97+
Assertions.assertInstanceOf(IllegalArgumentException.class, cause);
9598

9699
Assertions.assertEquals(
97-
KeyPartTypeChecker.COMPOSITE_KEY_FIELD_DIFFERENT_EXCEPTION, exception.getMessage());
100+
KeyPartTypeChecker.COMPOSITE_KEY_FIELD_DIFFERENT_EXCEPTION, cause.getMessage());
98101
}
99102

100103
@Test
101104
void testCreateEntityWithWrongCompositeKeyPartCount() {
102105
Set<Class<?>> initialSet =
103-
new HashSet<Class<?>>() {
106+
new HashSet<>() {
104107
{
105108
add(EntityWithWrongCompositeKeyPartsCount.class);
106109
}
107110
};
108-
IllegalArgumentException exception =
109-
assertThrows(IllegalArgumentException.class, () -> initEntities(initialSet));
110-
111-
assertEquals(KeyPartTypeChecker.COMPOSITE_KEY_FIELDS_NUMBER_EXCEPTION, exception.getMessage());
111+
MappingException exception =
112+
assertThrows(MappingException.class, () -> initEntities(initialSet));
113+
final Throwable cause = exception.getCause();
114+
Assertions.assertInstanceOf(IllegalArgumentException.class, cause);
115+
assertEquals(KeyPartTypeChecker.COMPOSITE_KEY_FIELDS_NUMBER_EXCEPTION, cause.getMessage());
112116
}
113117

114118
/**
115-
* Create a mappingContext from the passed domain classes. After initialize - create for them
116-
* PersistentEntities and add PersistentProperties to them.
117-
*
118-
* @param entitySet
119-
* @return
119+
* Create a mappingContext from the passed domain classes. After initialize - create for them PersistentEntities and
120+
* add PersistentProperties to them.
120121
*/
121-
private MappingContext<?, ?> initEntities(Set<Class<?>> entitySet) {
122+
private void initEntities(Set<Class<?>> entitySet) {
122123
TarantoolMappingContext<?, ?> mappingContext = new TarantoolMappingContext<>();
123124
mappingContext.setInitialEntitySet(entitySet);
124125
mappingContext.initialize();
125-
return mappingContext;
126126
}
127127

128128
private enum TestResolver implements KeySpaceResolver {
129129
INSTANCE;
130130

131131
@Override
132132
@Nullable
133-
public String resolveKeySpace(Class<?> type) {
133+
public String resolveKeySpace(@NonNull Class<?> type) {
134134

135135
Assert.notNull(type, "Type for keyspace for null!");
136136

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/core/mapping/model/PersistentCompositeIdIsNewStrategyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import static org.junit.jupiter.api.Assertions.assertFalse;
1111
import static org.junit.jupiter.api.Assertions.assertNotNull;
1212
import org.junit.jupiter.api.Test;
13+
import org.springframework.data.core.TypeInformation;
1314
import org.springframework.data.mapping.model.Property;
1415
import org.springframework.data.mapping.model.SimpleTypeHolder;
15-
import org.springframework.data.util.TypeInformation;
1616
import org.springframework.util.ReflectionUtils;
1717

1818
import io.tarantool.spring.data40.core.annotation.DefaultIdClassResolver;

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/query/TarantoolPageImplTest.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,14 @@ class TarantoolPageImplTest {
4343
private static final long MULTIPLIER = 2L;
4444

4545
private static final BiFunction<Integer, String, Long> GET_TOTAL_ELEMENTS_FOR_TEST_DATA_CASE =
46-
(pageSize, operator) -> {
47-
switch (operator) {
48-
// pageSize > totalPageCount
49-
case ">":
50-
{
51-
return pageSize / MULTIPLIER;
52-
}
53-
// pageSize < totalPageCount
54-
case "<":
55-
{
56-
return MULTIPLIER * pageSize;
57-
}
58-
// pageSize == totalPageCount
59-
case "==":
60-
{
61-
return Long.valueOf(pageSize);
62-
}
63-
default:
64-
throw new IllegalArgumentException("The passed option isn't supported");
65-
}
46+
(pageSize, operator) -> switch (operator) {
47+
// pageSize > totalPageCount
48+
case ">" -> pageSize / MULTIPLIER;
49+
// pageSize < totalPageCount
50+
case "<" -> MULTIPLIER * pageSize;
51+
// pageSize == totalPageCount
52+
case "==" -> Long.valueOf(pageSize);
53+
default -> throw new IllegalArgumentException("The passed option isn't supported");
6654
};
6755

6856
private static final List<Person> EMPTY_CONTENT = Collections.emptyList();

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/query/TarantoolPageRequestTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import java.util.stream.Stream;
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertFalse;
1415
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1516
import static org.junit.jupiter.api.Assertions.assertNull;
1617
import static org.junit.jupiter.api.Assertions.assertThrows;
17-
import static org.junit.jupiter.api.Assertions.assertTrue;
1818
import org.junit.jupiter.api.Test;
1919
import org.junit.jupiter.params.ParameterizedTest;
2020
import org.junit.jupiter.params.provider.Arguments;
@@ -254,15 +254,15 @@ void testEquals(
254254
List<TarantoolPageable<GenericPerson<?>>> equalPageableList,
255255
TarantoolPageable<GenericPerson<?>> notEqualPageable) {
256256

257-
assertTrue(equalPageableList.size() > 0);
257+
assertFalse(equalPageableList.isEmpty());
258258
final int COUNT = 10;
259259

260260
for (int i = 0; i < COUNT; i++) {
261261
for (TarantoolPageable<GenericPerson<?>> pageable : equalPageableList) {
262262
for (TarantoolPageable<GenericPerson<?>> secondPageable : equalPageableList) {
263263
assertEquals(pageable, secondPageable);
264264
}
265-
assertNotEquals(pageable, null);
265+
assertNotEquals(null, pageable);
266266
assertNotEquals(pageable, notEqualPageable);
267267
}
268268
}

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/query/TarantoolSliceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ <T> void testEquals(List<Slice<T>> equalPageableList, Slice<T> notEqualPageable)
520520
for (Slice<T> secondPageable : equalPageableList) {
521521
assertEquals(pageable, secondPageable);
522522
}
523-
assertNotEquals(pageable, null);
523+
assertNotEquals(null, pageable);
524524
assertNotEquals(pageable, notEqualPageable);
525525
}
526526
}

tarantool-spring-data/tarantool-spring-data-40/src/test/java/io/tarantool/spring/data40/utils/TarantoolTestSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.function.Consumer;
2525

2626
import static org.junit.jupiter.api.Assertions.assertEquals;
27-
import org.springframework.lang.NonNull;
28-
import org.springframework.lang.Nullable;
27+
import org.jspecify.annotations.NonNull;
28+
import org.jspecify.annotations.Nullable;
2929
import org.yaml.snakeyaml.DumperOptions;
3030
import org.yaml.snakeyaml.Yaml;
3131
import org.yaml.snakeyaml.introspector.Property;
@@ -278,7 +278,7 @@ public static PropertyInstanceConnectionGroup connectionGroup(
278278
@Nullable Integer connectionNumber,
279279
@Nullable String tag,
280280
@Nullable String user,
281-
@Nullable IProtoAuth.AuthType type,
281+
IProtoAuth.@Nullable AuthType type,
282282
@Nullable PropertyFlushConsolidationHandler propertyFlushConsolidationHandler) {
283283

284284
PropertyInstanceConnectionGroup propertyInstanceConnectionGroup =

0 commit comments

Comments
 (0)