Skip to content

Commit 72cbe58

Browse files
committed
DATAJDBC-207 - Polishing.
Formatting.
1 parent 3329a2a commit 72cbe58

File tree

5 files changed

+77
-64
lines changed

5 files changed

+77
-64
lines changed

src/test/java/org/springframework/data/jdbc/core/SqlGeneratorContextBasedNamingStrategyUnitTests.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public void cascadingDeleteAllSecondLevel() {
9797

9898
String sql = sqlGenerator.createDeleteByPath(PropertyPath.from("ref.further", DummyEntity.class));
9999

100-
assertThat(sql).isEqualTo(
101-
"DELETE FROM " + user + ".second_level_referenced_entity " +
102-
"WHERE " + user + ".referenced_entity IN " +
103-
"(SELECT l1id FROM " + user + ".referenced_entity " +
104-
"WHERE " + user + ".dummy_entity = :rootId)");
100+
assertThat(sql).isEqualTo( //
101+
"DELETE FROM " + user + ".second_level_referenced_entity " //
102+
+ "WHERE " + user + ".referenced_entity IN " //
103+
+ "(SELECT l1id FROM " + user + ".referenced_entity " //
104+
+ "WHERE " + user + ".dummy_entity = :rootId)");
105105
});
106106
}
107107

@@ -127,8 +127,8 @@ public void cascadingDeleteAllFirstLevel() {
127127

128128
String sql = sqlGenerator.createDeleteAllSql(PropertyPath.from("ref", DummyEntity.class));
129129

130-
assertThat(sql).isEqualTo(
131-
"DELETE FROM " + user + ".referenced_entity WHERE " + user + ".dummy_entity IS NOT NULL");
130+
assertThat(sql).isEqualTo( //
131+
"DELETE FROM " + user + ".referenced_entity WHERE " + user + ".dummy_entity IS NOT NULL");
132132
});
133133
}
134134

@@ -141,11 +141,11 @@ public void cascadingDeleteSecondLevel() {
141141

142142
String sql = sqlGenerator.createDeleteAllSql(PropertyPath.from("ref.further", DummyEntity.class));
143143

144-
assertThat(sql).isEqualTo(
145-
"DELETE FROM " + user + ".second_level_referenced_entity " +
146-
"WHERE " + user + ".referenced_entity IN " +
147-
"(SELECT l1id FROM " + user + ".referenced_entity " +
148-
"WHERE " + user + ".dummy_entity IS NOT NULL)");
144+
assertThat(sql).isEqualTo( //
145+
"DELETE FROM " + user + ".second_level_referenced_entity " //
146+
+ "WHERE " + user + ".referenced_entity IN " //
147+
+ "(SELECT l1id FROM " + user + ".referenced_entity " //
148+
+ "WHERE " + user + ".dummy_entity IS NOT NULL)");
149149
});
150150
}
151151

@@ -161,7 +161,7 @@ private void testAgainstMultipleUsers(Consumer<String> testAssertions) {
161161
threadedTest("User2", latch, testAssertions, exception);
162162

163163
try {
164-
if (!latch.await(10L, TimeUnit.SECONDS)){
164+
if (!latch.await(10L, TimeUnit.SECONDS)) {
165165
fail("Test failed due to a time out.");
166166
}
167167
} catch (InterruptedException e) {
@@ -175,10 +175,11 @@ private void testAgainstMultipleUsers(Consumer<String> testAssertions) {
175175
}
176176

177177
/**
178-
* Inside a {@link Runnable}, fetch the {@link ThreadLocal}-based username and execute the provided
179-
* set of assertions. Then signal through the provided {@link CountDownLatch}.
178+
* Inside a {@link Runnable}, fetch the {@link ThreadLocal}-based username and execute the provided set of assertions.
179+
* Then signal through the provided {@link CountDownLatch}.
180180
*/
181-
private void threadedTest(String user, CountDownLatch latch, Consumer<String> testAssertions, AtomicReference<Error> exception) {
181+
private void threadedTest(String user, CountDownLatch latch, Consumer<String> testAssertions,
182+
AtomicReference<Error> exception) {
182183

183184
new Thread(() -> {
184185

@@ -201,7 +202,12 @@ private void threadedTest(String user, CountDownLatch latch, Consumer<String> te
201202
*/
202203
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
203204

204-
JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {});
205+
JdbcMappingContext context = new JdbcMappingContext( //
206+
namingStrategy, //
207+
mock(NamedParameterJdbcOperations.class), //
208+
__ -> {} //
209+
);
210+
205211
JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
206212

207213
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));

src/test/java/org/springframework/data/jdbc/core/SqlGeneratorUnitTests.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public class SqlGeneratorUnitTests {
4646
public void setUp() {
4747

4848
NamingStrategy namingStrategy = new PrefixingNamingStrategy();
49-
JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {});
49+
JdbcMappingContext context = new JdbcMappingContext( //
50+
namingStrategy, //
51+
mock(NamedParameterJdbcOperations.class), //
52+
__ -> {} //
53+
);
54+
5055
JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
5156
this.sqlGenerator = new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
5257
}
@@ -128,14 +133,14 @@ public void findAllByPropertyWithKey() {
128133
// this would get called when DummyEntity is th element type of a Map
129134
String sql = sqlGenerator.getFindAllByProperty("back-ref", "key-column", false);
130135

131-
assertThat(sql).isEqualTo("SELECT dummy_entity.x_id AS x_id, dummy_entity.x_name AS x_name, "
132-
+ "ref.x_l1id AS ref_x_l1id, ref.x_content AS ref_x_content, ref.x_further AS ref_x_further, "
133-
+ "dummy_entity.key-column AS key-column "
134-
+ "FROM dummy_entity LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.x_id "
136+
assertThat(sql).isEqualTo("SELECT dummy_entity.x_id AS x_id, dummy_entity.x_name AS x_name, " //
137+
+ "ref.x_l1id AS ref_x_l1id, ref.x_content AS ref_x_content, ref.x_further AS ref_x_further, " //
138+
+ "dummy_entity.key-column AS key-column " //
139+
+ "FROM dummy_entity LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.x_id " //
135140
+ "WHERE back-ref = :back-ref");
136141
}
137142

138-
@Test (expected = IllegalArgumentException.class) // DATAJDBC-130
143+
@Test(expected = IllegalArgumentException.class) // DATAJDBC-130
139144
public void findAllByPropertyOrderedWithoutKey() {
140145
String sql = sqlGenerator.getFindAllByProperty("back-ref", null, true);
141146
}
@@ -146,13 +151,12 @@ public void findAllByPropertyWithKeyOrdered() {
146151
// this would get called when DummyEntity is th element type of a Map
147152
String sql = sqlGenerator.getFindAllByProperty("back-ref", "key-column", true);
148153

149-
assertThat(sql).isEqualTo("SELECT dummy_entity.x_id AS x_id, dummy_entity.x_name AS x_name, "
150-
+ "ref.x_l1id AS ref_x_l1id, ref.x_content AS ref_x_content, ref.x_further AS ref_x_further, "
151-
+ "dummy_entity.key-column AS key-column "
152-
+ "FROM dummy_entity LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.x_id "
153-
+ "WHERE back-ref = :back-ref "
154-
+ "ORDER BY key-column"
155-
);
154+
assertThat(sql).isEqualTo("SELECT dummy_entity.x_id AS x_id, dummy_entity.x_name AS x_name, " //
155+
+ "ref.x_l1id AS ref_x_l1id, ref.x_content AS ref_x_content, ref.x_further AS ref_x_further, " //
156+
+ "dummy_entity.key-column AS key-column " //
157+
+ "FROM dummy_entity LEFT OUTER JOIN referenced_entity AS ref ON ref.dummy_entity = dummy_entity.x_id " //
158+
+ "WHERE back-ref = :back-ref " //
159+
+ "ORDER BY key-column");
156160
}
157161

158162
@SuppressWarnings("unused")

src/test/java/org/springframework/data/jdbc/core/conversion/JdbcEntityWriterUnitTests.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public void newEntityWithMapResultsInAdditionalInsertPerElement() {
195195
tuple(Insert.class, Element.class, "one", "elements"), //
196196
tuple(Insert.class, Element.class, "two", "elements") //
197197
).containsSubsequence( // container comes before the elements
198-
tuple(Insert.class, MapContainer.class, null, ""), //
199-
tuple(Insert.class, Element.class, "two", "elements") //
200-
).containsSubsequence( // container comes before the elements
201-
tuple(Insert.class, MapContainer.class, null, ""), //
202-
tuple(Insert.class, Element.class, "one", "elements") //
198+
tuple(Insert.class, MapContainer.class, null, ""), //
199+
tuple(Insert.class, Element.class, "two", "elements") //
200+
).containsSubsequence( // container comes before the elements
201+
tuple(Insert.class, MapContainer.class, null, ""), //
202+
tuple(Insert.class, Element.class, "one", "elements") //
203203
);
204204
}
205205

@@ -239,7 +239,7 @@ public void newEntityWithFullMapResultsInAdditionalInsertPerElement() {
239239
tuple(Insert.class, Element.class, "0", "elements"), //
240240
tuple(Insert.class, Element.class, "a", "elements"), //
241241
tuple(Insert.class, Element.class, "b", "elements") //
242-
);
242+
);
243243
}
244244

245245
@Test // DATAJDBC-130
@@ -259,8 +259,8 @@ public void newEntityWithEmptyListResultsInSingleInsert() {
259259
public void newEntityWithListResultsInAdditionalInsertPerElement() {
260260

261261
ListContainer entity = new ListContainer(null);
262-
entity.elements.add( new Element(null));
263-
entity.elements.add( new Element(null));
262+
entity.elements.add(new Element(null));
263+
entity.elements.add(new Element(null));
264264

265265
AggregateChange<ListContainer> aggregateChange = new AggregateChange(Kind.SAVE, ListContainer.class, entity);
266266
converter.write(entity, aggregateChange);
@@ -272,11 +272,11 @@ public void newEntityWithListResultsInAdditionalInsertPerElement() {
272272
tuple(Insert.class, Element.class, 0, "elements"), //
273273
tuple(Insert.class, Element.class, 1, "elements") //
274274
).containsSubsequence( // container comes before the elements
275-
tuple(Insert.class, ListContainer.class, null, ""), //
276-
tuple(Insert.class, Element.class, 1, "elements") //
277-
).containsSubsequence( // container comes before the elements
278-
tuple(Insert.class, ListContainer.class, null, ""), //
279-
tuple(Insert.class, Element.class, 0, "elements") //
275+
tuple(Insert.class, ListContainer.class, null, ""), //
276+
tuple(Insert.class, Element.class, 1, "elements") //
277+
).containsSubsequence( // container comes before the elements
278+
tuple(Insert.class, ListContainer.class, null, ""), //
279+
tuple(Insert.class, Element.class, 0, "elements") //
280280
);
281281
}
282282

@@ -296,14 +296,14 @@ public void mapTriggersDeletePlusInsert() {
296296
tuple(Delete.class, Element.class, null, "elements"), //
297297
tuple(Update.class, MapContainer.class, null, ""), //
298298
tuple(Insert.class, Element.class, "one", "elements") //
299-
);
299+
);
300300
}
301301

302302
@Test // DATAJDBC-130
303303
public void listTriggersDeletePlusInsert() {
304304

305305
ListContainer entity = new ListContainer(SOME_ENTITY_ID);
306-
entity.elements.add( new Element(null));
306+
entity.elements.add(new Element(null));
307307

308308
AggregateChange<ListContainer> aggregateChange = new AggregateChange(Kind.SAVE, ListContainer.class, entity);
309309

@@ -315,7 +315,7 @@ public void listTriggersDeletePlusInsert() {
315315
tuple(Delete.class, Element.class, null, "elements"), //
316316
tuple(Update.class, ListContainer.class, null, ""), //
317317
tuple(Insert.class, Element.class, 0, "elements") //
318-
);
318+
);
319319
}
320320

321321
private CascadingReferenceMiddleElement createMiddleElement(Element first, Element second) {
@@ -379,7 +379,7 @@ private static class MapContainer {
379379
private static class ListContainer {
380380

381381
@Id final Long id;
382-
List< Element> elements = new ArrayList<>();
382+
List<Element> elements = new ArrayList<>();
383383
}
384384

385385
@RequiredArgsConstructor

src/test/java/org/springframework/data/jdbc/mapping/model/NamingStrategyUnitTests.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,27 @@ public class NamingStrategyUnitTests {
3737

3838
private final NamingStrategy target = NamingStrategy.INSTANCE;
3939

40-
private final JdbcPersistentEntity<?> persistentEntity =
41-
new JdbcMappingContext(target, mock(NamedParameterJdbcOperations.class), mock(ConversionCustomizer.class))
42-
.getRequiredPersistentEntity(DummyEntity.class);
40+
private final JdbcPersistentEntity<?> persistentEntity = //
41+
new JdbcMappingContext(target, //
42+
mock(NamedParameterJdbcOperations.class), //
43+
mock(ConversionCustomizer.class)) //
44+
.getRequiredPersistentEntity(DummyEntity.class);
4345

4446
@Test // DATAJDBC-184
4547
public void getTableName() {
46-
assertThat(target.getTableName(persistentEntity.getType()))
48+
49+
assertThat(target.getTableName(persistentEntity.getType())) //
4750
.isEqualTo("dummy_entity");
4851
}
4952

5053
@Test // DATAJDBC-184
5154
public void getColumnName() {
52-
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("id")))
55+
56+
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("id"))) //
5357
.isEqualTo("id");
54-
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("createdAt")))
58+
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("createdAt"))) //
5559
.isEqualTo("created_at");
56-
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("dummySubEntities")))
60+
assertThat(target.getColumnName(persistentEntity.getPersistentProperty("dummySubEntities"))) //
5761
.isEqualTo("dummy_sub_entities");
5862
}
5963

@@ -65,34 +69,34 @@ public void getReverseColumnName() {
6569

6670
@Test // DATAJDBC-184
6771
public void getKeyColumn() {
68-
assertThat(target.getKeyColumn(persistentEntity.getPersistentProperty("dummySubEntities")))
72+
73+
assertThat(target.getKeyColumn(persistentEntity.getPersistentProperty("dummySubEntities"))) //
6974
.isEqualTo("dummy_entity_key");
7075
}
7176

7277
@Test // DATAJDBC-184
7378
public void getSchema() {
74-
assertThat(target.getSchema())
75-
.isEmpty();
79+
assertThat(target.getSchema()).isEmpty();
7680
}
7781

7882
@Test // DATAJDBC-184
7983
public void getQualifiedTableName() {
80-
assertThat(target.getQualifiedTableName(persistentEntity.getType()))
81-
.isEqualTo("dummy_entity");
84+
85+
assertThat(target.getQualifiedTableName(persistentEntity.getType())).isEqualTo("dummy_entity");
8286
}
8387

8488
@Data
8589
private static class DummyEntity {
86-
@Id
87-
private int id;
90+
91+
@Id private int id;
8892
private LocalDateTime createdAt;
8993
private List<DummySubEntity> dummySubEntities;
9094
}
9195

9296
@Data
9397
private static class DummySubEntity {
94-
@Id
95-
private int id;
98+
99+
@Id private int id;
96100
private LocalDateTime createdAt;
97101
}
98102

src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ DummyEntityRepository dummyEntityRepository() {
6666

6767
}
6868

69-
7069
@ClassRule public static final SpringClassRule classRule = new SpringClassRule();
7170
@Rule public SpringMethodRule methodRule = new SpringMethodRule();
7271

0 commit comments

Comments
 (0)