Skip to content

Commit 7690cef

Browse files
DATAJDBC-378 - Polishing
Move non integration tests to separate class. Original Pull Request: #155
1 parent 688eeca commit 7690cef

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 lombok.Data;
22+
23+
import javax.sql.DataSource;
24+
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.MockitoJUnitRunner;
30+
import org.springframework.context.ApplicationEventPublisher;
31+
import org.springframework.data.annotation.Id;
32+
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
33+
import org.springframework.data.relational.core.conversion.RelationalConverter;
34+
import org.springframework.data.relational.core.mapping.Column;
35+
import org.springframework.data.relational.core.mapping.NamingStrategy;
36+
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
37+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
38+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
39+
40+
/**
41+
* @author Christoph Strobl
42+
*/
43+
@RunWith(MockitoJUnitRunner.class)
44+
public class JdbcAggregateTemplateUnitTests {
45+
46+
JdbcAggregateOperations template;
47+
48+
@Mock ApplicationEventPublisher eventPublisher;
49+
@Mock DataSource dataSource;
50+
51+
@Before
52+
public void setUp() {
53+
54+
RelationalMappingContext mappingContext = new RelationalMappingContext(NamingStrategy.INSTANCE);
55+
RelationalConverter converter = new BasicRelationalConverter(mappingContext);
56+
NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
57+
DataAccessStrategy dataAccessStrategy = new DefaultDataAccessStrategy(new SqlGeneratorSource(mappingContext),
58+
mappingContext, converter, namedParameterJdbcOperations);
59+
template = new JdbcAggregateTemplate(eventPublisher, mappingContext, converter, dataAccessStrategy);
60+
}
61+
62+
@Test // DATAJDBC-378
63+
public void findAllByIdMustNotAcceptNullArgumentForType() {
64+
assertThatThrownBy(() -> template.findAllById(singleton(23L), null)).isInstanceOf(IllegalArgumentException.class);
65+
}
66+
67+
@Test // DATAJDBC-378
68+
public void findAllByIdMustNotAcceptNullArgumentForIds() {
69+
70+
assertThatThrownBy(() -> template.findAllById(null, SampleEntity.class))
71+
.isInstanceOf(IllegalArgumentException.class);
72+
}
73+
74+
@Test // DATAJDBC-378
75+
public void findAllByIdWithEmpthListMustReturnEmptyResult() {
76+
assertThat(template.findAllById(emptyList(), SampleEntity.class)).isEmpty();
77+
}
78+
79+
@Data
80+
private static class SampleEntity {
81+
82+
@Column("id1") @Id private Long id;
83+
84+
private String name;
85+
}
86+
}

0 commit comments

Comments
 (0)