Skip to content

Commit 6469607

Browse files
authored
Merge pull request #214 from jeffgbutler/master
Refactor Tests per SonarQube
2 parents ebf824b + c04a37b commit 6469607

File tree

52 files changed

+1674
-1704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1674
-1704
lines changed

pom.xml

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

src/test/java/examples/animal/data/AnimalDataTest.java

Lines changed: 232 additions & 233 deletions
Large diffs are not rendered by default.

src/test/java/examples/animal/data/BindingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 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.
@@ -41,15 +41,15 @@
4141
* Tests for understanding where bind parameters are allowed
4242
*
4343
*/
44-
public class BindingTest {
44+
class BindingTest {
4545

4646
private static final String JDBC_URL = "jdbc:hsqldb:mem:aname";
4747
private static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver";
4848

4949
private SqlSessionFactory sqlSessionFactory;
5050

5151
@BeforeEach
52-
public void setup() throws Exception {
52+
void setup() throws Exception {
5353
Class.forName(JDBC_DRIVER);
5454
InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
5555
try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
@@ -66,7 +66,7 @@ public void setup() throws Exception {
6666
}
6767

6868
@Test
69-
public void testBindInSelectList() {
69+
void testBindInSelectList() {
7070
SqlSession sqlSession = sqlSessionFactory.openSession();
7171
try {
7272
Connection connection = sqlSession.getConnection();
@@ -93,7 +93,7 @@ public void testBindInSelectList() {
9393
}
9494

9595
@Test
96-
public void testBindInWeirdWhere() {
96+
void testBindInWeirdWhere() {
9797
SqlSession sqlSession = sqlSessionFactory.openSession();
9898
try {
9999
Connection connection = sqlSession.getConnection();

src/test/java/examples/animal/data/FetchFirstTest.java

Lines changed: 24 additions & 24 deletions
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.
@@ -39,15 +39,15 @@
3939
import org.mybatis.dynamic.sql.render.RenderingStrategies;
4040
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
4141

42-
public class FetchFirstTest {
42+
class FetchFirstTest {
4343

4444
private static final String JDBC_URL = "jdbc:hsqldb:mem:aname";
4545
private static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver";
4646

4747
private SqlSessionFactory sqlSessionFactory;
4848

4949
@BeforeEach
50-
public void setup() throws Exception {
50+
void setup() throws Exception {
5151
Class.forName(JDBC_DRIVER);
5252
InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
5353
try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
@@ -64,7 +64,7 @@ public void setup() throws Exception {
6464
}
6565

6666
@Test
67-
public void testOffsetAndFetchFirstAfterFrom() {
67+
void testOffsetAndFetchFirstAfterFrom() {
6868
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
6969
SelectStatementProvider selectStatement = select(animalData.allColumns())
7070
.from(animalData)
@@ -77,17 +77,17 @@ public void testOffsetAndFetchFirstAfterFrom() {
7777
List<AnimalData> records = mapper.selectMany(selectStatement);
7878

7979
assertAll(
80-
() -> assertThat(records.size()).isEqualTo(3),
80+
() -> assertThat(records).hasSize(3),
8181
() -> assertThat(records.get(0).getId()).isEqualTo(23),
8282
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData offset #{parameters.p1} rows fetch first #{parameters.p2} rows only"),
83-
() -> assertThat(selectStatement.getParameters().get("p2")).isEqualTo(3L),
84-
() -> assertThat(selectStatement.getParameters().get("p1")).isEqualTo(22L)
83+
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L),
84+
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
8585
);
8686
}
8787
}
8888

8989
@Test
90-
public void testFetchFirstOnlyAfterFrom() {
90+
void testFetchFirstOnlyAfterFrom() {
9191
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9292
SelectStatementProvider selectStatement = select(animalData.allColumns())
9393
.from(animalData)
@@ -99,16 +99,16 @@ public void testFetchFirstOnlyAfterFrom() {
9999
List<AnimalData> records = mapper.selectMany(selectStatement);
100100

101101
assertAll(
102-
() -> assertThat(records.size()).isEqualTo(3),
102+
() -> assertThat(records).hasSize(3),
103103
() -> assertThat(records.get(0).getId()).isEqualTo(1),
104104
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData fetch first #{parameters.p1} rows only"),
105-
() -> assertThat(selectStatement.getParameters().get("p1")).isEqualTo(3L)
105+
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
106106
);
107107
}
108108
}
109109

110110
@Test
111-
public void testOffsetAndFetchFirstAfterWhere() {
111+
void testOffsetAndFetchFirstAfterWhere() {
112112
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
113113
SelectStatementProvider selectStatement = select(animalData.allColumns())
114114
.from(animalData)
@@ -123,17 +123,17 @@ public void testOffsetAndFetchFirstAfterWhere() {
123123
List<AnimalData> records = mapper.selectMany(selectStatement);
124124

125125
assertAll(
126-
() -> assertThat(records.size()).isEqualTo(3),
126+
() -> assertThat(records).hasSize(3),
127127
() -> assertThat(records.get(0).getId()).isEqualTo(45),
128128
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} and id > #{parameters.p2,jdbcType=INTEGER} offset #{parameters.p3} rows fetch first #{parameters.p4} rows only"),
129-
() -> assertThat(selectStatement.getParameters().get("p4")).isEqualTo(3L),
130-
() -> assertThat(selectStatement.getParameters().get("p3")).isEqualTo(22L)
129+
() -> assertThat(selectStatement.getParameters()).containsEntry("p4", 3L),
130+
() -> assertThat(selectStatement.getParameters()).containsEntry("p3", 22L)
131131
);
132132
}
133133
}
134134

135135
@Test
136-
public void testFetchFirstOnlyAfterWhere() {
136+
void testFetchFirstOnlyAfterWhere() {
137137
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
138138
SelectStatementProvider selectStatement = select(animalData.allColumns())
139139
.from(animalData)
@@ -146,16 +146,16 @@ public void testFetchFirstOnlyAfterWhere() {
146146
List<AnimalData> records = mapper.selectMany(selectStatement);
147147

148148
assertAll(
149-
() -> assertThat(records.size()).isEqualTo(3),
149+
() -> assertThat(records).hasSize(3),
150150
() -> assertThat(records.get(0).getId()).isEqualTo(1),
151151
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} fetch first #{parameters.p2} rows only"),
152-
() -> assertThat(selectStatement.getParameters().get("p2")).isEqualTo(3L)
152+
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L)
153153
);
154154
}
155155
}
156156

157157
@Test
158-
public void testOffsetAndFetchFirstAfterOrderBy() {
158+
void testOffsetAndFetchFirstAfterOrderBy() {
159159
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
160160
SelectStatementProvider selectStatement = select(animalData.allColumns())
161161
.from(animalData)
@@ -169,17 +169,17 @@ public void testOffsetAndFetchFirstAfterOrderBy() {
169169
List<AnimalData> records = mapper.selectMany(selectStatement);
170170

171171
assertAll(
172-
() -> assertThat(records.size()).isEqualTo(3),
172+
() -> assertThat(records).hasSize(3),
173173
() -> assertThat(records.get(0).getId()).isEqualTo(23),
174174
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id offset #{parameters.p1} rows fetch first #{parameters.p2} rows only"),
175-
() -> assertThat(selectStatement.getParameters().get("p2")).isEqualTo(3L),
176-
() -> assertThat(selectStatement.getParameters().get("p1")).isEqualTo(22L)
175+
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L),
176+
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
177177
);
178178
}
179179
}
180180

181181
@Test
182-
public void testLimitOnlyAfterOrderBy() {
182+
void testLimitOnlyAfterOrderBy() {
183183
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
184184
SelectStatementProvider selectStatement = select(animalData.allColumns())
185185
.from(animalData)
@@ -192,10 +192,10 @@ public void testLimitOnlyAfterOrderBy() {
192192
List<AnimalData> records = mapper.selectMany(selectStatement);
193193

194194
assertAll(
195-
() -> assertThat(records.size()).isEqualTo(3),
195+
() -> assertThat(records).hasSize(3),
196196
() -> assertThat(records.get(0).getId()).isEqualTo(1),
197197
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id fetch first #{parameters.p1} rows only"),
198-
() -> assertThat(selectStatement.getParameters().get("p1")).isEqualTo(3L)
198+
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
199199
);
200200
}
201201
}

0 commit comments

Comments
 (0)