Skip to content

Commit 8e3e194

Browse files
committed
Improve tests per Sonar recs
1 parent a03ab7f commit 8e3e194

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/test/java/org/mybatis/dynamic/sql/StatementConfigurationTest.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@
2727
import static org.mybatis.dynamic.sql.SqlBuilder.update;
2828

2929
import org.junit.jupiter.api.Test;
30+
import org.mybatis.dynamic.sql.delete.DeleteModel;
3031
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
3132
import org.mybatis.dynamic.sql.exception.UnrenderableWhereClauseException;
3233
import org.mybatis.dynamic.sql.render.RenderingStrategies;
34+
import org.mybatis.dynamic.sql.select.SelectModel;
3335
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
36+
import org.mybatis.dynamic.sql.update.UpdateModel;
3437
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
3538

36-
public class StatementConfigurationTest {
39+
class StatementConfigurationTest {
3740
@Test
3841
void testCountWhereCalledButNoCriteriaThrowsException() {
42+
SelectModel selectModel = countFrom(person)
43+
.where()
44+
.build();
45+
3946
assertThatExceptionOfType(UnrenderableWhereClauseException.class).isThrownBy(() ->
40-
countFrom(person)
41-
.where()
42-
.build()
43-
.render(RenderingStrategies.MYBATIS3)
47+
selectModel.render(RenderingStrategies.MYBATIS3)
4448
);
4549
}
4650

@@ -52,8 +56,7 @@ void testCountWhereCalledButNoCriteriaRequiresConfiguration() {
5256
.build()
5357
.render(RenderingStrategies.MYBATIS3);
5458

55-
assertThat(selectStatement.getSelectStatement())
56-
.isEqualTo("select count(*) from Person");
59+
assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from Person");
5760
}
5861

5962
@Test
@@ -62,17 +65,17 @@ void testCountWhereNotCalledIsOK() {
6265
.build()
6366
.render(RenderingStrategies.MYBATIS3);
6467

65-
assertThat(selectStatement.getSelectStatement())
66-
.isEqualTo("select count(*) from Person");
68+
assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from Person");
6769
}
6870

6971
@Test
7072
void testDeleteWhereCalledButNoCriteriaThrowsException() {
73+
DeleteModel deleteModel = deleteFrom(person)
74+
.where()
75+
.build();
76+
7177
assertThatExceptionOfType(UnrenderableWhereClauseException.class).isThrownBy(() ->
72-
deleteFrom(person)
73-
.where()
74-
.build()
75-
.render(RenderingStrategies.MYBATIS3)
78+
deleteModel.render(RenderingStrategies.MYBATIS3)
7679
);
7780
}
7881

@@ -84,8 +87,7 @@ void testDeleteWhereCalledButNoCriteriaRequiresConfiguration() {
8487
.build()
8588
.render(RenderingStrategies.MYBATIS3);
8689

87-
assertThat(deleteStatement.getDeleteStatement())
88-
.isEqualTo("delete from Person");
90+
assertThat(deleteStatement.getDeleteStatement()).isEqualTo("delete from Person");
8991
}
9092

9193
@Test
@@ -94,18 +96,18 @@ void testDeleteWhereNotCalledIsOK() {
9496
.build()
9597
.render(RenderingStrategies.MYBATIS3);
9698

97-
assertThat(deleteStatement.getDeleteStatement())
98-
.isEqualTo("delete from Person");
99+
assertThat(deleteStatement.getDeleteStatement()).isEqualTo("delete from Person");
99100
}
100101

101102
@Test
102103
void testSelectWhereCalledButNoCriteriaThrowsException() {
104+
SelectModel selectModel = select(id, firstName, lastName)
105+
.from(person)
106+
.where()
107+
.build();
108+
103109
assertThatExceptionOfType(UnrenderableWhereClauseException.class).isThrownBy(() ->
104-
select(id, firstName, lastName)
105-
.from(person)
106-
.where()
107-
.build()
108-
.render(RenderingStrategies.MYBATIS3)
110+
selectModel.render(RenderingStrategies.MYBATIS3)
109111
);
110112
}
111113

@@ -135,12 +137,13 @@ void testSelectWhereNotCalledIsOK() {
135137

136138
@Test
137139
void testUpdateWhereCalledButNoCriteriaThrowsException() {
140+
UpdateModel updateModel = update(person)
141+
.set(id).equalTo(1)
142+
.where()
143+
.build();
144+
138145
assertThatExceptionOfType(UnrenderableWhereClauseException.class).isThrownBy(() ->
139-
update(person)
140-
.set(id).equalTo(1)
141-
.where()
142-
.build()
143-
.render(RenderingStrategies.MYBATIS3)
146+
updateModel.render(RenderingStrategies.MYBATIS3)
144147
);
145148
}
146149

0 commit comments

Comments
 (0)