Skip to content

Commit c70c6db

Browse files
DATAJDBC-378 - Polishing
Move non integration tests to separate class.
1 parent caedb1f commit c70c6db

File tree

3 files changed

+92
-31
lines changed

3 files changed

+92
-31
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* @author Jens Schauder
4747
* @author Mark Paluch
4848
* @author Thomas Lang
49+
* @author Christoph Strobl
4950
*/
5051
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
5152

@@ -165,8 +166,8 @@ public long count(Class<?> domainType) {
165166
@Override
166167
public <T> T findById(Object id, Class<T> domainType) {
167168

168-
Assert.notNull(id, "Id must not be null");
169-
Assert.notNull(domainType, "Domain type must not be null");
169+
Assert.notNull(id, "Id must not be null!");
170+
Assert.notNull(domainType, "Domain type must not be null!");
170171

171172
T entity = accessStrategy.findById(id, domainType);
172173
if (entity != null) {
@@ -182,8 +183,8 @@ public <T> T findById(Object id, Class<T> domainType) {
182183
@Override
183184
public <T> boolean existsById(Object id, Class<T> domainType) {
184185

185-
Assert.notNull(id, "Id must not be null");
186-
Assert.notNull(domainType, "Domain type must not be null");
186+
Assert.notNull(id, "Id must not be null!");
187+
Assert.notNull(domainType, "Domain type must not be null!");
187188

188189
return accessStrategy.existsById(id, domainType);
189190
}
@@ -195,7 +196,7 @@ public <T> boolean existsById(Object id, Class<T> domainType) {
195196
@Override
196197
public <T> Iterable<T> findAll(Class<T> domainType) {
197198

198-
Assert.notNull(domainType, "Domain type must not be null");
199+
Assert.notNull(domainType, "Domain type must not be null!");
199200

200201
Iterable<T> all = accessStrategy.findAll(domainType);
201202
publishAfterLoad(all);
@@ -209,8 +210,8 @@ public <T> Iterable<T> findAll(Class<T> domainType) {
209210
@Override
210211
public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
211212

212-
Assert.notNull(ids, "Ids must not be null");
213-
Assert.notNull(domainType, "Domain type must not be null");
213+
Assert.notNull(ids, "Ids must not be null!");
214+
Assert.notNull(domainType, "Domain type must not be null!");
214215

215216
Iterable<T> allById = accessStrategy.findAllById(ids, domainType);
216217
publishAfterLoad(allById);
@@ -224,8 +225,8 @@ public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
224225
@Override
225226
public <S> void delete(S aggregateRoot, Class<S> domainType) {
226227

227-
Assert.notNull(aggregateRoot, "Aggregate root must not be null");
228-
Assert.notNull(domainType, "Domain type must not be null");
228+
Assert.notNull(aggregateRoot, "Aggregate root must not be null!");
229+
Assert.notNull(domainType, "Domain type must not be null!");
229230

230231
IdentifierAccessor identifierAccessor = context.getRequiredPersistentEntity(domainType)
231232
.getIdentifierAccessor(aggregateRoot);
@@ -240,8 +241,8 @@ public <S> void delete(S aggregateRoot, Class<S> domainType) {
240241
@Override
241242
public <S> void deleteById(Object id, Class<S> domainType) {
242243

243-
Assert.notNull(id, "Id must not be null");
244-
Assert.notNull(domainType, "Domain type must not be null");
244+
Assert.notNull(id, "Id must not be null!");
245+
Assert.notNull(domainType, "Domain type must not be null!");
245246

246247
deleteTree(id, null, domainType);
247248
}
@@ -253,7 +254,7 @@ public <S> void deleteById(Object id, Class<S> domainType) {
253254
@Override
254255
public void deleteAll(Class<?> domainType) {
255256

256-
Assert.notNull(domainType, "Domain type must not be null");
257+
Assert.notNull(domainType, "Domain type must not be null!");
257258

258259
AggregateChange<?> change = createDeletingChange(domainType);
259260
change.executeWith(interpreter, context, converter);
@@ -274,7 +275,7 @@ private <T> T store(T instance, IdentifierAccessor identifierAccessor, Aggregate
274275

275276
Object identifier = persistentEntity.getIdentifierAccessor(change.getEntity()).getIdentifier();
276277

277-
Assert.notNull(identifier, "After saving the identifier must not be null");
278+
Assert.notNull(identifier, "After saving the identifier must not be null!");
278279

279280
publisher.publishEvent(new AfterSaveEvent( //
280281
Identifier.of(identifier), //

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,6 @@ public void shouldDeleteChainOfMapsWithoutIds() {
596596
});
597597
}
598598

599-
@Test // DATAJDBC-378
600-
public void findAllByIdMustNotAcceptNullArgumentForType() {
601-
602-
assertThatThrownBy(() -> template.findAllById(singleton(23L), null)).isInstanceOf(IllegalArgumentException.class);
603-
}
604-
605-
@Test // DATAJDBC-378
606-
public void findAllByIdMustNotAcceptNullArgumentForIds() {
607-
608-
assertThatThrownBy(() -> template.findAllById(null, LegoSet.class)).isInstanceOf(IllegalArgumentException.class);
609-
}
610-
611-
@Test // DATAJDBC-378
612-
public void findAllByIdWithEmpthListMustReturnEmptyResult() {
613-
614-
assertThat(template.findAllById(emptyList(), LegoSet.class)).isEmpty();
615-
}
616-
617599
private static NoIdMapChain4 createNoIdMapTree() {
618600

619601
NoIdMapChain4 chain4 = new NoIdMapChain4();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.core;
17+
18+
import static java.util.Collections.*;
19+
import static org.assertj.core.api.Assertions.*;
20+
21+
import javax.sql.DataSource;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.mockito.Mock;
27+
import org.mockito.junit.MockitoJUnitRunner;
28+
import org.springframework.context.ApplicationEventPublisher;
29+
import org.springframework.data.jdbc.core.JdbcAggregateTemplateIntegrationTests.LegoSet;
30+
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
31+
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
32+
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
33+
import org.springframework.data.jdbc.core.convert.JdbcConverter;
34+
import org.springframework.data.jdbc.core.convert.RelationResolver;
35+
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
36+
import org.springframework.data.relational.core.mapping.NamingStrategy;
37+
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
38+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
39+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
40+
41+
/**
42+
* @author Christoph Strobl
43+
*/
44+
@RunWith(MockitoJUnitRunner.class)
45+
public class JdbcAggregateTemplateUnitTests {
46+
47+
JdbcAggregateOperations template;
48+
49+
@Mock ApplicationEventPublisher eventPublisher;
50+
@Mock RelationResolver relationResolver;
51+
@Mock DataSource dataSource;
52+
53+
@Before
54+
public void setUp() {
55+
56+
RelationalMappingContext mappingContext = new RelationalMappingContext(NamingStrategy.INSTANCE);
57+
JdbcConverter converter = new BasicJdbcConverter(mappingContext, relationResolver);
58+
NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
59+
DataAccessStrategy dataAccessStrategy = new DefaultDataAccessStrategy(new SqlGeneratorSource(mappingContext),
60+
mappingContext, converter, namedParameterJdbcOperations);
61+
template = new JdbcAggregateTemplate(eventPublisher, mappingContext, converter, dataAccessStrategy);
62+
}
63+
64+
@Test // DATAJDBC-378
65+
public void findAllByIdMustNotAcceptNullArgumentForType() {
66+
assertThatThrownBy(() -> template.findAllById(singleton(23L), null)).isInstanceOf(IllegalArgumentException.class);
67+
}
68+
69+
@Test // DATAJDBC-378
70+
public void findAllByIdMustNotAcceptNullArgumentForIds() {
71+
assertThatThrownBy(() -> template.findAllById(null, LegoSet.class)).isInstanceOf(IllegalArgumentException.class);
72+
}
73+
74+
@Test // DATAJDBC-378
75+
public void findAllByIdWithEmpthListMustReturnEmptyResult() {
76+
assertThat(template.findAllById(emptyList(), LegoSet.class)).isEmpty();
77+
}
78+
}

0 commit comments

Comments
 (0)