Skip to content

Commit 6f8e47d

Browse files
committed
Polishing based on review.
Use static import for `SoftAssertions.assertSoftly` everywhere. Polishing of the conversion filter. See #974
1 parent 3a21a43 commit 6f8e47d

17 files changed

+73
-59
lines changed

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcCustomConversions.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import java.util.Collection;
1919
import java.util.Collections;
2020
import java.util.List;
21-
import java.util.function.Predicate;
2221

23-
import org.springframework.core.convert.converter.GenericConverter;
2422
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
2523
import org.springframework.data.convert.CustomConversions;
2624
import org.springframework.data.jdbc.core.mapping.JdbcSimpleTypes;
@@ -43,8 +41,6 @@ public class JdbcCustomConversions extends CustomConversions {
4341
private static final StoreConversions STORE_CONVERSIONS = StoreConversions.of(JdbcSimpleTypes.HOLDER,
4442
STORE_CONVERTERS);
4543

46-
private static final Predicate<ConvertiblePair> excludeConversionsBetweenDateAndJsr310Types= cp -> !isDateTimeApiConversion(cp);
47-
4844
/**
4945
* Creates an empty {@link JdbcCustomConversions} object.
5046
*/
@@ -59,7 +55,12 @@ public JdbcCustomConversions() {
5955
* @param converters must not be {@literal null}.
6056
*/
6157
public JdbcCustomConversions(List<?> converters) {
62-
super(new ConverterConfiguration(STORE_CONVERSIONS, converters, excludeConversionsBetweenDateAndJsr310Types));
58+
59+
super(new ConverterConfiguration( //
60+
STORE_CONVERSIONS, //
61+
converters, //
62+
JdbcCustomConversions::excludeConversionsBetweenDateAndJsr310Types //
63+
));
6364
}
6465

6566
/**
@@ -69,7 +70,12 @@ public JdbcCustomConversions(List<?> converters) {
6970
* @since 2.3
7071
*/
7172
public JdbcCustomConversions(StoreConversions storeConversions, List<?> userConverters) {
72-
super(new ConverterConfiguration(storeConversions, userConverters, cp -> !isDateTimeApiConversion(cp)));
73+
74+
super(new ConverterConfiguration( //
75+
storeConversions, //
76+
userConverters, //
77+
JdbcCustomConversions::excludeConversionsBetweenDateAndJsr310Types //
78+
));
7379
}
7480

7581
/**
@@ -105,4 +111,8 @@ private static boolean isDateTimeApiConversion(ConvertiblePair cp) {
105111

106112
return false;
107113
}
114+
115+
private static boolean excludeConversionsBetweenDateAndJsr310Types(ConvertiblePair cp) {
116+
return !isDateTimeApiConversion(cp);
117+
}
108118
}

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AggregateChangeIdGenerationUnitTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static java.util.Collections.*;
1919
import static org.assertj.core.api.Assertions.*;
20+
import static org.assertj.core.api.SoftAssertions.*;
2021
import static org.mockito.Mockito.*;
2122

2223
import java.util.ArrayList;
@@ -26,7 +27,6 @@
2627
import java.util.Map;
2728
import java.util.Set;
2829

29-
import org.assertj.core.api.SoftAssertions;
3030
import org.junit.jupiter.api.Test;
3131
import org.mockito.invocation.InvocationOnMock;
3232
import org.mockito.stubbing.Answer;
@@ -87,7 +87,7 @@ public void simpleReference() {
8787

8888
executor.execute(aggregateChange);
8989

90-
SoftAssertions.assertSoftly(softly -> {
90+
assertSoftly(softly -> {
9191

9292
softly.assertThat(entity.rootId).isEqualTo(1);
9393
softly.assertThat(entity.single.id).isEqualTo(2);
@@ -107,7 +107,7 @@ public void listReference() {
107107

108108
executor.execute(aggregateChange);
109109

110-
SoftAssertions.assertSoftly(softly -> {
110+
assertSoftly(softly -> {
111111

112112
softly.assertThat(entity.rootId).isEqualTo(1);
113113
softly.assertThat(entity.contentList).extracting(c -> c.id).containsExactly(2, 3);
@@ -171,7 +171,7 @@ public void setIdForDeepReferenceElementList() {
171171

172172
executor.execute(aggregateChange);
173173

174-
SoftAssertions.assertSoftly(softly -> {
174+
assertSoftly(softly -> {
175175

176176
softly.assertThat(entity.rootId).isEqualTo(1);
177177
softly.assertThat(entity.single.id).isEqualTo(2);
@@ -198,7 +198,7 @@ public void setIdForDeepElementSetElementSet() {
198198

199199
executor.execute(aggregateChange);
200200

201-
SoftAssertions.assertSoftly(softly -> {
201+
assertSoftly(softly -> {
202202

203203
softly.assertThat(entity.rootId).isEqualTo(1);
204204
softly.assertThat(entity.contentSet) //
@@ -233,7 +233,7 @@ public void setIdForDeepElementListSingleReference() {
233233

234234
executor.execute(aggregateChange);
235235

236-
SoftAssertions.assertSoftly(softly -> {
236+
assertSoftly(softly -> {
237237

238238
softly.assertThat(entity.rootId).isEqualTo(1);
239239
softly.assertThat(entity.contentList) //
@@ -267,7 +267,7 @@ public void setIdForDeepElementListElementList() {
267267

268268
executor.execute(aggregateChange);
269269

270-
SoftAssertions.assertSoftly(softly -> {
270+
assertSoftly(softly -> {
271271

272272
softly.assertThat(entity.rootId).isEqualTo(1);
273273
softly.assertThat(entity.contentList) //
@@ -305,7 +305,7 @@ public void setIdForDeepElementMapElementMap() {
305305

306306
executor.execute(aggregateChange);
307307

308-
SoftAssertions.assertSoftly(softly -> {
308+
assertSoftly(softly -> {
309309

310310
softly.assertThat(entity.rootId).isEqualTo(1);
311311
softly.assertThat(entity.contentMap.entrySet()) //

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static java.util.Collections.*;
1919
import static org.assertj.core.api.Assertions.*;
20+
import static org.assertj.core.api.SoftAssertions.*;
2021
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
2122
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
2223

@@ -664,7 +665,7 @@ public void shouldDeleteChainOfListsWithoutIds() {
664665
NoIdListChain4 saved = template.save(createNoIdTree());
665666
template.deleteById(saved.four, NoIdListChain4.class);
666667

667-
SoftAssertions.assertSoftly(softly -> {
668+
assertSoftly(softly -> {
668669

669670
softly.assertThat(count("NO_ID_LIST_CHAIN4")).describedAs("Chain4 elements got deleted").isEqualTo(0);
670671
softly.assertThat(count("NO_ID_LIST_CHAIN3")).describedAs("Chain3 elements got deleted").isEqualTo(0);
@@ -691,7 +692,7 @@ public void shouldDeleteChainOfMapsWithoutIds() {
691692
NoIdMapChain4 saved = template.save(createNoIdMapTree());
692693
template.deleteById(saved.four, NoIdMapChain4.class);
693694

694-
SoftAssertions.assertSoftly(softly -> {
695+
assertSoftly(softly -> {
695696

696697
softly.assertThat(count("NO_ID_MAP_CHAIN4")).describedAs("Chain4 elements got deleted").isEqualTo(0);
697698
softly.assertThat(count("NO_ID_MAP_CHAIN3")).describedAs("Chain3 elements got deleted").isEqualTo(0);

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverterUnitTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.jdbc.core.convert;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.assertj.core.api.SoftAssertions.*;
1920
import static org.mockito.Mockito.*;
2021

2122
import lombok.Data;
@@ -119,7 +120,7 @@ void conversionOfDateLikeValueAndBackYieldsOriginalValue() {
119120

120121
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
121122

122-
SoftAssertions.assertSoftly(softly -> {
123+
assertSoftly(softly -> {
123124
LocalDateTime testLocalDateTime = LocalDateTime.of(2001, 2, 3, 4, 5, 6, 123456789);
124125
checkConversionToTimestampAndBack(softly, persistentEntity, "localDateTime", testLocalDateTime);
125126
checkConversionToTimestampAndBack(softly, persistentEntity, "localDate", LocalDate.of(2001, 2, 3));

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static java.util.Arrays.*;
1919
import static java.util.Collections.*;
2020
import static org.assertj.core.api.Assertions.*;
21+
import static org.assertj.core.api.SoftAssertions.*;
2122
import static org.mockito.ArgumentMatchers.*;
2223
import static org.mockito.Mockito.*;
2324

@@ -43,12 +44,10 @@
4344

4445
import javax.naming.OperationNotSupportedException;
4546

46-
import org.assertj.core.api.SoftAssertions;
4747
import org.junit.jupiter.api.Test;
4848
import org.mockito.ArgumentMatchers;
4949
import org.mockito.invocation.InvocationOnMock;
5050
import org.mockito.stubbing.Answer;
51-
5251
import org.springframework.data.annotation.Id;
5352
import org.springframework.data.annotation.PersistenceConstructor;
5453
import org.springframework.data.annotation.Transient;
@@ -1217,7 +1216,7 @@ private static class Fixture<T> {
12171216

12181217
public void assertOn(T result) {
12191218

1220-
SoftAssertions.assertSoftly(softly -> {
1219+
assertSoftly(softly -> {
12211220
expectations.forEach(expectation -> {
12221221

12231222
softly.assertThat(expectation.extractor.apply(result)).describedAs("From column: " + expectation.sourceColumn)

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdentifierUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.jdbc.core.convert;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.assertj.core.api.SoftAssertions.*;
1920
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
2021

2122
import java.util.ArrayList;
@@ -25,7 +26,6 @@
2526
import java.util.Map;
2627

2728
import org.assertj.core.api.Assertions;
28-
import org.assertj.core.api.SoftAssertions;
2929
import org.junit.jupiter.api.Test;
3030
import org.springframework.data.relational.core.sql.IdentifierProcessing;
3131
import org.springframework.data.relational.core.sql.SqlIdentifier;
@@ -125,7 +125,7 @@ public void identifierPartsCanBeAccessedByString() {
125125

126126
Map<SqlIdentifier, Object> map = id.toMap();
127127

128-
SoftAssertions.assertSoftly(softly -> {
128+
assertSoftly(softly -> {
129129
softly.assertThat(map.get("aName")).describedAs("aName").isEqualTo("one");
130130
softly.assertThat(map.get("Other")).describedAs("Other").isEqualTo("two");
131131
softly.assertThat(map.get("other")).describedAs("other").isNull();

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import static java.util.Collections.*;
1919
import static org.assertj.core.api.Assertions.*;
20+
import static org.assertj.core.api.SoftAssertions.*;
2021

21-
import org.assertj.core.api.SoftAssertions;
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Disabled;
2424
import org.junit.jupiter.api.Test;
@@ -42,7 +42,7 @@
4242
*/
4343
public class SqlGeneratorEmbeddedUnitTests {
4444

45-
private RelationalMappingContext context = new JdbcMappingContext();
45+
private final RelationalMappingContext context = new JdbcMappingContext();
4646
JdbcConverter converter = new BasicJdbcConverter(context, (identifier, path) -> {
4747
throw new UnsupportedOperationException();
4848
});
@@ -63,7 +63,7 @@ SqlGenerator createSqlGenerator(Class<?> type) {
6363
public void findOne() {
6464
final String sql = sqlGenerator.getFindOne();
6565

66-
SoftAssertions.assertSoftly(softly -> {
66+
assertSoftly(softly -> {
6767

6868
softly.assertThat(sql).startsWith("SELECT") //
6969
.contains("dummy_entity.id1 AS id1") //
@@ -86,7 +86,7 @@ public void findOne() {
8686
public void findAll() {
8787
final String sql = sqlGenerator.getFindAll();
8888

89-
SoftAssertions.assertSoftly(softly -> {
89+
assertSoftly(softly -> {
9090

9191
softly.assertThat(sql).startsWith("SELECT") //
9292
.contains("dummy_entity.id1 AS id1") //
@@ -109,7 +109,7 @@ public void findAll() {
109109
public void findAllInList() {
110110
final String sql = sqlGenerator.getFindAllInList();
111111

112-
SoftAssertions.assertSoftly(softly -> {
112+
assertSoftly(softly -> {
113113

114114
softly.assertThat(sql).startsWith("SELECT") //
115115
.contains("dummy_entity.id1 AS id1") //
@@ -132,7 +132,7 @@ public void findAllInList() {
132132
public void insert() {
133133
final String sql = sqlGenerator.getInsert(emptySet());
134134

135-
SoftAssertions.assertSoftly(softly -> {
135+
assertSoftly(softly -> {
136136

137137
softly.assertThat(sql) //
138138
.startsWith("INSERT INTO") //
@@ -154,7 +154,7 @@ public void insert() {
154154
public void update() {
155155
final String sql = sqlGenerator.getUpdate();
156156

157-
SoftAssertions.assertSoftly(softly -> {
157+
assertSoftly(softly -> {
158158

159159
softly.assertThat(sql) //
160160
.startsWith("UPDATE") //
@@ -267,7 +267,7 @@ public void joinForEmbeddedWithReference() {
267267

268268
SqlGenerator.Join join = generateJoin("embedded.other", DummyEntity2.class);
269269

270-
SoftAssertions.assertSoftly(softly -> {
270+
assertSoftly(softly -> {
271271

272272
softly.assertThat(join.getJoinTable().getName()).isEqualTo(SqlIdentifier.unquoted("other_entity"));
273273
softly.assertThat(join.getJoinColumn().getTable()).isEqualTo(join.getJoinTable());

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static java.util.Collections.*;
1919
import static org.assertj.core.api.Assertions.*;
20+
import static org.assertj.core.api.SoftAssertions.*;
2021
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
2122

2223
import java.util.Map;
@@ -94,7 +95,7 @@ public void findOne() {
9495

9596
String sql = sqlGenerator.getFindOne();
9697

97-
SoftAssertions.assertSoftly(softly -> softly //
98+
assertSoftly(softly -> softly //
9899
.assertThat(sql) //
99100
.startsWith("SELECT") //
100101
.contains("dummy_entity.id1 AS id1,") //
@@ -113,7 +114,7 @@ public void getAcquireLockById() {
113114

114115
String sql = sqlGenerator.getAcquireLockById(LockMode.PESSIMISTIC_WRITE);
115116

116-
SoftAssertions.assertSoftly(softly -> softly //
117+
assertSoftly(softly -> softly //
117118
.assertThat(sql) //
118119
.startsWith("SELECT") //
119120
.contains("dummy_entity.id1") //
@@ -127,7 +128,7 @@ public void getAcquireLockAll() {
127128

128129
String sql = sqlGenerator.getAcquireLockAll(LockMode.PESSIMISTIC_WRITE);
129130

130-
SoftAssertions.assertSoftly(softly -> softly //
131+
assertSoftly(softly -> softly //
131132
.assertThat(sql) //
132133
.startsWith("SELECT") //
133134
.contains("dummy_entity.id1") //
@@ -580,7 +581,7 @@ public void joinForSimpleReference() {
580581

581582
SqlGenerator.Join join = generateJoin("ref", DummyEntity.class);
582583

583-
SoftAssertions.assertSoftly(softly -> {
584+
assertSoftly(softly -> {
584585

585586
softly.assertThat(join.getJoinTable().getName()).isEqualTo(SqlIdentifier.quoted("REFERENCED_ENTITY"));
586587
softly.assertThat(join.getJoinColumn().getTable()).isEqualTo(join.getJoinTable());
@@ -612,7 +613,7 @@ public void joinForSecondLevelReference() {
612613

613614
SqlGenerator.Join join = generateJoin("ref.further", DummyEntity.class);
614615

615-
SoftAssertions.assertSoftly(softly -> {
616+
assertSoftly(softly -> {
616617

617618
softly.assertThat(join.getJoinTable().getName())
618619
.isEqualTo(SqlIdentifier.quoted("SECOND_LEVEL_REFERENCED_ENTITY"));
@@ -629,7 +630,7 @@ public void joinForOneToOneWithoutId() {
629630
SqlGenerator.Join join = generateJoin("child", ParentOfNoIdChild.class);
630631
Table joinTable = join.getJoinTable();
631632

632-
SoftAssertions.assertSoftly(softly -> {
633+
assertSoftly(softly -> {
633634

634635
softly.assertThat(joinTable.getName()).isEqualTo(SqlIdentifier.quoted("NO_ID_CHILD"));
635636
softly.assertThat(joinTable).isInstanceOf(Aliased.class);

0 commit comments

Comments
 (0)