Skip to content

Commit 9063963

Browse files
committed
Polishing.
Simplifying test code
1 parent 06c9858 commit 9063963

File tree

1 file changed

+61
-143
lines changed

1 file changed

+61
-143
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverterUnitTests.java

+61-143
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
class MappingJdbcConverterUnitTests {
6060

6161
private static final UUID UUID = java.util.UUID.fromString("87a48aa8-a071-705e-54a9-e52fe3a012f1");
62-
private static final byte[] BYTES_REPRESENTING_UUID = { -121, -92, -118, -88, -96, 113, 112, 94, 84, -87, -27, 47,
62+
private static final byte[] BYTES_REPRESENTING_UUID = {-121, -92, -118, -88, -96, 113, 112, 94, 84, -87, -27, 47,
6363
-29,
64-
-96, 18, -15 };
64+
-96, 18, -15};
6565

6666
private JdbcMappingContext context = new JdbcMappingContext();
6767
private StubbedJdbcTypeFactory typeFactory = new StubbedJdbcTypeFactory();
@@ -74,28 +74,29 @@ class MappingJdbcConverterUnitTests {
7474
typeFactory //
7575
);
7676

77-
@Test // DATAJDBC-104, DATAJDBC-1384
77+
@Test
78+
// DATAJDBC-104, DATAJDBC-1384
7879
void testTargetTypesForPropertyType() {
7980

8081
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
8182

82-
SoftAssertions softly = new SoftAssertions();
83-
84-
checkTargetType(softly, entity, "someEnum", String.class);
85-
checkTargetType(softly, entity, "localDateTime", LocalDateTime.class);
86-
checkTargetType(softly, entity, "localDate", Timestamp.class);
87-
checkTargetType(softly, entity, "localTime", Timestamp.class);
88-
checkTargetType(softly, entity, "zonedDateTime", String.class);
89-
checkTargetType(softly, entity, "offsetDateTime", OffsetDateTime.class);
90-
checkTargetType(softly, entity, "instant", Timestamp.class);
91-
checkTargetType(softly, entity, "date", Date.class);
92-
checkTargetType(softly, entity, "timestamp", Timestamp.class);
93-
checkTargetType(softly, entity, "uuid", UUID.class);
94-
95-
softly.assertAll();
83+
SoftAssertions.assertSoftly(softly -> {
84+
85+
checkTargetType(softly, entity, "someEnum", String.class);
86+
checkTargetType(softly, entity, "localDateTime", LocalDateTime.class);
87+
checkTargetType(softly, entity, "localDate", Timestamp.class);
88+
checkTargetType(softly, entity, "localTime", Timestamp.class);
89+
checkTargetType(softly, entity, "zonedDateTime", String.class);
90+
checkTargetType(softly, entity, "offsetDateTime", OffsetDateTime.class);
91+
checkTargetType(softly, entity, "instant", Timestamp.class);
92+
checkTargetType(softly, entity, "date", Date.class);
93+
checkTargetType(softly, entity, "timestamp", Timestamp.class);
94+
checkTargetType(softly, entity, "uuid", UUID.class);
95+
});
9696
}
9797

98-
@Test // DATAJDBC-259
98+
@Test
99+
// DATAJDBC-259
99100
void classificationOfCollectionLikeProperties() {
100101

101102
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
@@ -111,22 +112,24 @@ void classificationOfCollectionLikeProperties() {
111112
softly.assertAll();
112113
}
113114

114-
@Test // DATAJDBC-221
115+
@Test
116+
// DATAJDBC-221
115117
void referencesAreNotEntitiesAndGetStoredAsTheirId() {
116118

117119
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
118120

119-
SoftAssertions softly = new SoftAssertions();
120121

121122
RelationalPersistentProperty reference = entity.getRequiredPersistentProperty("reference");
122123

123-
softly.assertThat(reference.isEntity()).isFalse();
124-
softly.assertThat(converter.getColumnType(reference)).isEqualTo(Long.class);
124+
SoftAssertions.assertSoftly(softly -> {
125125

126-
softly.assertAll();
126+
softly.assertThat(reference.isEntity()).isFalse();
127+
softly.assertThat(converter.getColumnType(reference)).isEqualTo(Long.class);
128+
});
127129
}
128130

129-
@Test // DATAJDBC-637
131+
@Test
132+
// DATAJDBC-637
130133
void conversionOfDateLikeValueAndBackYieldsOriginalValue() {
131134

132135
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
@@ -142,17 +145,19 @@ void conversionOfDateLikeValueAndBackYieldsOriginalValue() {
142145

143146
}
144147

145-
@Test // GH-945
148+
@Test
149+
// GH-945
146150
void conversionOfPrimitiveArrays() {
147151

148-
int[] ints = { 1, 2, 3, 4, 5 };
152+
int[] ints = {1, 2, 3, 4, 5};
149153
JdbcValue converted = converter.writeJdbcValue(ints, ints.getClass(), JdbcUtil.targetSqlTypeFor(ints.getClass()));
150154

151155
assertThat(converted.getValue()).isInstanceOf(Array.class);
152156
assertThat(typeFactory.arraySource).containsExactly(1, 2, 3, 4, 5);
153157
}
154158

155-
@Test // GH-1684
159+
@Test
160+
// GH-1684
156161
void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdProperties() {
157162

158163
RowDocument rowdocument = new RowDocument(Map.of("ID", "one", "REFERENCED_ID", 23));
@@ -162,7 +167,8 @@ void accessesCorrectValuesForOneToOneRelationshipWithIdenticallyNamedIdPropertie
162167
assertThat(result).isEqualTo(new WithOneToOne("one", new Referenced(23L)));
163168
}
164169

165-
@Test // GH-1750
170+
@Test
171+
// GH-1750
166172
void readByteArrayToNestedUuidWithCustomConverter() {
167173

168174
JdbcMappingContext context = new JdbcMappingContext();
@@ -186,7 +192,7 @@ void readByteArrayToNestedUuidWithCustomConverter() {
186192
}
187193

188194
private static void checkReadConversion(SoftAssertions softly, MappingJdbcConverter converter, String propertyName,
189-
Object expected) {
195+
Object expected) {
190196

191197
RelationalPersistentProperty property = converter.getMappingContext().getRequiredPersistentEntity(DummyEntity.class)
192198
.getRequiredPersistentProperty(propertyName);
@@ -197,7 +203,7 @@ private static void checkReadConversion(SoftAssertions softly, MappingJdbcConver
197203
}
198204

199205
private void checkConversionToTimestampAndBack(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
200-
String propertyName, Object value) {
206+
String propertyName, Object value) {
201207

202208
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
203209

@@ -208,125 +214,36 @@ private void checkConversionToTimestampAndBack(SoftAssertions softly, Relational
208214
}
209215

210216
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
211-
String propertyName, Class<?> expected) {
217+
String propertyName, Class<?> expected) {
212218

213219
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
214220

215221
softly.assertThat(converter.getColumnType(property)).describedAs(propertyName).isEqualTo(expected);
216222
}
217223

218224
@SuppressWarnings("unused")
219-
private static class DummyEntity {
220-
221-
@Id private final Long id;
222-
private final SomeEnum someEnum;
223-
private final LocalDateTime localDateTime;
224-
private final LocalDate localDate;
225-
private final LocalTime localTime;
226-
private final ZonedDateTime zonedDateTime;
227-
private final OffsetDateTime offsetDateTime;
228-
private final Instant instant;
229-
private final Date date;
230-
private final Timestamp timestamp;
231-
private final AggregateReference<DummyEntity, Long> reference;
232-
private final UUID uuid;
233-
private final AggregateReference<ReferencedByUuid, UUID> uuidRef;
234-
private final Optional<UUID> optionalUuid;
235-
236-
// DATAJDBC-259
237-
private final List<String> listOfString;
238-
private final String[] arrayOfString;
239-
private final List<OtherEntity> listOfEntity;
240-
private final OtherEntity[] arrayOfEntity;
241-
242-
private DummyEntity(Long id, SomeEnum someEnum, LocalDateTime localDateTime, LocalDate localDate,
243-
LocalTime localTime, ZonedDateTime zonedDateTime, OffsetDateTime offsetDateTime, Instant instant, Date date,
244-
Timestamp timestamp, AggregateReference<DummyEntity, Long> reference, UUID uuid,
245-
AggregateReference<ReferencedByUuid, UUID> uuidRef, Optional<java.util.UUID> optionalUUID, List<String> listOfString, String[] arrayOfString,
246-
List<OtherEntity> listOfEntity, OtherEntity[] arrayOfEntity) {
247-
this.id = id;
248-
this.someEnum = someEnum;
249-
this.localDateTime = localDateTime;
250-
this.localDate = localDate;
251-
this.localTime = localTime;
252-
this.zonedDateTime = zonedDateTime;
253-
this.offsetDateTime = offsetDateTime;
254-
this.instant = instant;
255-
this.date = date;
256-
this.timestamp = timestamp;
257-
this.reference = reference;
258-
this.uuid = uuid;
259-
this.uuidRef = uuidRef;
260-
this.optionalUuid = optionalUUID;
261-
this.listOfString = listOfString;
262-
this.arrayOfString = arrayOfString;
263-
this.listOfEntity = listOfEntity;
264-
this.arrayOfEntity = arrayOfEntity;
265-
}
266-
267-
public Long getId() {
268-
return this.id;
269-
}
270-
271-
public SomeEnum getSomeEnum() {
272-
return this.someEnum;
273-
}
274-
275-
public LocalDateTime getLocalDateTime() {
276-
return this.localDateTime;
277-
}
278-
279-
public LocalDate getLocalDate() {
280-
return this.localDate;
281-
}
282-
283-
public LocalTime getLocalTime() {
284-
return this.localTime;
285-
}
286-
287-
public ZonedDateTime getZonedDateTime() {
288-
return this.zonedDateTime;
289-
}
290-
291-
public OffsetDateTime getOffsetDateTime() {
292-
return this.offsetDateTime;
293-
}
294-
295-
public Instant getInstant() {
296-
return this.instant;
297-
}
298-
299-
public Date getDate() {
300-
return this.date;
301-
}
302-
303-
public Timestamp getTimestamp() {
304-
return this.timestamp;
305-
}
306-
307-
public AggregateReference<DummyEntity, Long> getReference() {
308-
return this.reference;
309-
}
310-
311-
public UUID getUuid() {
312-
return this.uuid;
313-
}
314-
315-
public List<String> getListOfString() {
316-
return this.listOfString;
317-
}
318-
319-
public String[] getArrayOfString() {
320-
return this.arrayOfString;
321-
}
322-
323-
public List<OtherEntity> getListOfEntity() {
324-
return this.listOfEntity;
325-
}
326-
327-
public OtherEntity[] getArrayOfEntity() {
328-
return this.arrayOfEntity;
329-
}
225+
private record DummyEntity(
226+
@Id Long id,
227+
SomeEnum someEnum,
228+
LocalDateTime localDateTime,
229+
LocalDate localDate,
230+
LocalTime localTime,
231+
ZonedDateTime zonedDateTime,
232+
OffsetDateTime offsetDateTime,
233+
Instant instant,
234+
Date date,
235+
Timestamp timestamp,
236+
AggregateReference<DummyEntity, Long> reference,
237+
UUID uuid,
238+
AggregateReference<ReferencedByUuid, UUID> uuidRef,
239+
Optional<UUID> optionalUuid,
240+
241+
// DATAJDBC-259
242+
List<String> listOfString,
243+
String[] arrayOfString,
244+
List<OtherEntity> listOfEntity,
245+
OtherEntity[] arrayOfEntity
246+
) {
330247
}
331248

332249
@SuppressWarnings("unused")
@@ -335,7 +252,8 @@ private enum SomeEnum {
335252
}
336253

337254
@SuppressWarnings("unused")
338-
private static class OtherEntity {}
255+
private static class OtherEntity {
256+
}
339257

340258
private static class StubbedJdbcTypeFactory implements JdbcTypeFactory {
341259
Object[] arraySource;

0 commit comments

Comments
 (0)