Skip to content

Commit a668283

Browse files
committed
Copyright, Test refactoring, etc.
1 parent 137eaa6 commit a668283

File tree

8 files changed

+139
-63
lines changed

8 files changed

+139
-63
lines changed

src/main/java/org/mybatis/dynamic/sql/util/AbstractColumnMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/test/java/examples/custom_render/CustomRenderingTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.testcontainers.junit.jupiter.Testcontainers;
4343

4444
@Testcontainers
45-
public class CustomRenderingTest {
45+
class CustomRenderingTest {
4646

4747
@Container
4848
private static PgContainer postgres = new PgContainer("examples/custom_render/dbInit.sql");
@@ -69,69 +69,69 @@ void resetDatabase() {
6969
}
7070

7171
@Test
72-
public void testInsert() {
72+
void testInsert() {
7373
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7474
JsonTestMapper mapper = sqlSession.getMapper(JsonTestMapper.class);
7575

76-
JsonTest record = new JsonTest();
76+
JsonTestRecord record = new JsonTestRecord();
7777
record.setId(1);
7878
record.setDescription("Fred");
7979
record.setInfo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
8080

8181
int rows = mapper.insert(record);
8282
assertThat(rows).isEqualTo(1);
8383

84-
record = new JsonTest();
84+
record = new JsonTestRecord();
8585
record.setId(2);
8686
record.setDescription("Wilma");
8787
record.setInfo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
8888

8989
rows = mapper.insert(record);
9090
assertThat(rows).isEqualTo(1);
9191

92-
List<JsonTest> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
92+
List<JsonTestRecord> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
9393
assertThat(records.size()).isEqualTo(2);
9494
assertThat(records.get(0).getInfo()).isEqualTo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
9595
assertThat(records.get(1).getInfo()).isEqualTo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
9696
}
9797
}
9898

9999
@Test
100-
public void testInsertMultiple() {
100+
void testInsertMultiple() {
101101
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
102102
JsonTestMapper mapper = sqlSession.getMapper(JsonTestMapper.class);
103103

104-
JsonTest record1 = new JsonTest();
104+
JsonTestRecord record1 = new JsonTestRecord();
105105
record1.setId(1);
106106
record1.setDescription("Fred");
107107
record1.setInfo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
108108

109-
JsonTest record2 = new JsonTest();
109+
JsonTestRecord record2 = new JsonTestRecord();
110110
record2.setId(2);
111111
record2.setDescription("Wilma");
112112
record2.setInfo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
113113

114114
int rows = mapper.insertMultiple(record1, record2);
115115
assertThat(rows).isEqualTo(2);
116116

117-
List<JsonTest> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
117+
List<JsonTestRecord> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
118118
assertThat(records.size()).isEqualTo(2);
119119
assertThat(records.get(0).getInfo()).isEqualTo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
120120
assertThat(records.get(1).getInfo()).isEqualTo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
121121
}
122122
}
123123

124124
@Test
125-
public void testUpdate() {
125+
void testUpdate() {
126126
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
127127
JsonTestMapper mapper = sqlSession.getMapper(JsonTestMapper.class);
128128

129-
JsonTest record1 = new JsonTest();
129+
JsonTestRecord record1 = new JsonTestRecord();
130130
record1.setId(1);
131131
record1.setDescription("Fred");
132132
record1.setInfo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
133133

134-
JsonTest record2 = new JsonTest();
134+
JsonTestRecord record2 = new JsonTestRecord();
135135
record2.setId(2);
136136
record2.setDescription("Wilma");
137137
record2.setInfo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
@@ -145,32 +145,32 @@ public void testUpdate() {
145145
);
146146
assertThat(rows).isEqualTo(1);
147147

148-
List<JsonTest> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
148+
List<JsonTestRecord> records = mapper.selectMany(SelectDSLCompleter.allRowsOrderedBy(id));
149149
assertThat(records.size()).isEqualTo(2);
150150
assertThat(records.get(0).getInfo()).isEqualTo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
151151
assertThat(records.get(1).getInfo()).isEqualTo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 26}");
152152
}
153153
}
154154

155155
@Test
156-
public void testDefererence() {
156+
void testDefererence() {
157157
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
158158
JsonTestMapper mapper = sqlSession.getMapper(JsonTestMapper.class);
159159

160-
JsonTest record1 = new JsonTest();
160+
JsonTestRecord record1 = new JsonTestRecord();
161161
record1.setId(1);
162162
record1.setDescription("Fred");
163163
record1.setInfo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
164164

165-
JsonTest record2 = new JsonTest();
165+
JsonTestRecord record2 = new JsonTestRecord();
166166
record2.setId(2);
167167
record2.setDescription("Wilma");
168168
record2.setInfo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
169169

170170
int rows = mapper.insertMultiple(record1, record2);
171171
assertThat(rows).isEqualTo(2);
172172

173-
Optional<JsonTest> record = mapper.selectOne(c ->
173+
Optional<JsonTestRecord> record = mapper.selectOne(c ->
174174
c.where(dereference(info, "age"), isEqualTo("25")));
175175

176176
assertThat(record).hasValueSatisfying( c ->
@@ -179,16 +179,16 @@ public void testDefererence() {
179179
}
180180

181181
@Test
182-
public void testDefererence2() {
182+
void testDefererence2() {
183183
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
184184
JsonTestMapper mapper = sqlSession.getMapper(JsonTestMapper.class);
185185

186-
JsonTest record1 = new JsonTest();
186+
JsonTestRecord record1 = new JsonTestRecord();
187187
record1.setId(1);
188188
record1.setDescription("Fred");
189189
record1.setInfo("{\"firstName\": \"Fred\", \"lastName\": \"Flintstone\", \"age\": 30}");
190190

191-
JsonTest record2 = new JsonTest();
191+
JsonTestRecord record2 = new JsonTestRecord();
192192
record2.setId(2);
193193
record2.setDescription("Wilma");
194194
record2.setInfo("{\"firstName\": \"Wilma\", \"lastName\": \"Flintstone\", \"age\": 25}");
@@ -203,8 +203,8 @@ public void testDefererence2() {
203203
.render(RenderingStrategies.MYBATIS3);
204204

205205
List<Map<String, Object>> records = mapper.generalSelect(selectStatement);
206-
assertThat(records.size()).isEqualTo(1);
207-
assertThat(records.get(0).get("firstname")).isEqualTo("Wilma");
206+
assertThat(records).hasSize(1);
207+
assertThat(records.get(0)).containsEntry("firstname", "Wilma");
208208
}
209209
}
210210

src/test/java/examples/custom_render/JsonTest.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/test/java/examples/custom_render/JsonTestDynamicSqlSupport.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2016-2020 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+
* http://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+
*/
116
package examples.custom_render;
217

318
import java.sql.JDBCType;

src/test/java/examples/custom_render/JsonTestMapper.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2016-2020 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+
* http://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+
*/
116
package examples.custom_render;
217

318
import static examples.custom_render.JsonTestDynamicSqlSupport.*;
@@ -37,11 +52,11 @@ public interface JsonTestMapper {
3752
@Result(column = "description", property = "description"),
3853
@Result(column = "info", property = "info")
3954
})
40-
List<JsonTest> selectMany(SelectStatementProvider selectStatement);
55+
List<JsonTestRecord> selectMany(SelectStatementProvider selectStatement);
4156

4257
@SelectProvider(type = SqlProviderAdapter.class, method = "select")
4358
@ResultMap("JsonTestResult")
44-
Optional<JsonTest> selectOne(SelectStatementProvider selectStatement);
59+
Optional<JsonTestRecord> selectOne(SelectStatementProvider selectStatement);
4560

4661
@DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
4762
int delete(DeleteStatementProvider deleteStatement);
@@ -50,39 +65,39 @@ public interface JsonTestMapper {
5065
int update(UpdateStatementProvider updateStatement);
5166

5267
@InsertProvider(type = SqlProviderAdapter.class, method = "insert")
53-
int insert(InsertStatementProvider<JsonTest> insertStatement);
68+
int insert(InsertStatementProvider<JsonTestRecord> insertStatement);
5469

5570
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
56-
int insertMultiple(MultiRowInsertStatementProvider<JsonTest> insertStatement);
71+
int insertMultiple(MultiRowInsertStatementProvider<JsonTestRecord> insertStatement);
5772

5873
BasicColumn[] selectList =
5974
BasicColumn.columnList(id, description, info);
6075

61-
default int insert(JsonTest record) {
76+
default int insert(JsonTestRecord record) {
6277
return MyBatis3Utils.insert(this::insert, record, jsonTest, c ->
6378
c.map(id).toProperty("id")
6479
.map(description).toProperty("description")
6580
.map(info).toProperty("info")
6681
);
6782
}
6883

69-
default int insertMultiple(JsonTest...records) {
84+
default int insertMultiple(JsonTestRecord...records) {
7085
return insertMultiple(Arrays.asList(records));
7186
}
7287

73-
default int insertMultiple(Collection<JsonTest> records) {
88+
default int insertMultiple(Collection<JsonTestRecord> records) {
7489
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, jsonTest, c ->
7590
c.map(id).toProperty("id")
7691
.map(description).toProperty("description")
7792
.map(info).toProperty("info")
7893
);
7994
}
8095

81-
default List<JsonTest> selectMany(SelectDSLCompleter completer) {
96+
default List<JsonTestRecord> selectMany(SelectDSLCompleter completer) {
8297
return MyBatis3Utils.selectList(this::selectMany, selectList, jsonTest, completer);
8398
}
8499

85-
default Optional<JsonTest> selectOne(SelectDSLCompleter completer) {
100+
default Optional<JsonTestRecord> selectOne(SelectDSLCompleter completer) {
86101
return MyBatis3Utils.selectOne(this::selectOne, selectList, jsonTest, completer);
87102
}
88103

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright 2016-2020 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+
* http://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 examples.custom_render;
17+
18+
public class JsonTestRecord {
19+
private int id;
20+
private String description;
21+
private String info;
22+
23+
public int getId() {
24+
return id;
25+
}
26+
27+
public void setId(int id) {
28+
this.id = id;
29+
}
30+
31+
public String getDescription() {
32+
return description;
33+
}
34+
35+
public void setDescription(String description) {
36+
this.description = description;
37+
}
38+
39+
public String getInfo() {
40+
return info;
41+
}
42+
43+
public void setInfo(String info) {
44+
this.info = info;
45+
}
46+
}

src/test/java/examples/custom_render/PgContainer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2016-2020 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+
* http://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+
*/
116
package examples.custom_render;
217

318
import javax.sql.DataSource;

src/test/resources/examples/custom_render/dbInit.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
--
2+
-- Copyright 2016-2020 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+
-- http://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+
117
create table JsonTest (
218
id int not null,
319
description varchar(30) not null,

0 commit comments

Comments
 (0)