27
27
import static org .mybatis .dynamic .sql .SqlBuilder .update ;
28
28
29
29
import org .junit .jupiter .api .Test ;
30
+ import org .mybatis .dynamic .sql .delete .DeleteModel ;
30
31
import org .mybatis .dynamic .sql .delete .render .DeleteStatementProvider ;
31
32
import org .mybatis .dynamic .sql .exception .UnrenderableWhereClauseException ;
32
33
import org .mybatis .dynamic .sql .render .RenderingStrategies ;
34
+ import org .mybatis .dynamic .sql .select .SelectModel ;
33
35
import org .mybatis .dynamic .sql .select .render .SelectStatementProvider ;
36
+ import org .mybatis .dynamic .sql .update .UpdateModel ;
34
37
import org .mybatis .dynamic .sql .update .render .UpdateStatementProvider ;
35
38
36
- public class StatementConfigurationTest {
39
+ class StatementConfigurationTest {
37
40
@ Test
38
41
void testCountWhereCalledButNoCriteriaThrowsException () {
42
+ SelectModel selectModel = countFrom (person )
43
+ .where ()
44
+ .build ();
45
+
39
46
assertThatExceptionOfType (UnrenderableWhereClauseException .class ).isThrownBy (() ->
40
- countFrom (person )
41
- .where ()
42
- .build ()
43
- .render (RenderingStrategies .MYBATIS3 )
47
+ selectModel .render (RenderingStrategies .MYBATIS3 )
44
48
);
45
49
}
46
50
@@ -52,8 +56,7 @@ void testCountWhereCalledButNoCriteriaRequiresConfiguration() {
52
56
.build ()
53
57
.render (RenderingStrategies .MYBATIS3 );
54
58
55
- assertThat (selectStatement .getSelectStatement ())
56
- .isEqualTo ("select count(*) from Person" );
59
+ assertThat (selectStatement .getSelectStatement ()).isEqualTo ("select count(*) from Person" );
57
60
}
58
61
59
62
@ Test
@@ -62,17 +65,17 @@ void testCountWhereNotCalledIsOK() {
62
65
.build ()
63
66
.render (RenderingStrategies .MYBATIS3 );
64
67
65
- assertThat (selectStatement .getSelectStatement ())
66
- .isEqualTo ("select count(*) from Person" );
68
+ assertThat (selectStatement .getSelectStatement ()).isEqualTo ("select count(*) from Person" );
67
69
}
68
70
69
71
@ Test
70
72
void testDeleteWhereCalledButNoCriteriaThrowsException () {
73
+ DeleteModel deleteModel = deleteFrom (person )
74
+ .where ()
75
+ .build ();
76
+
71
77
assertThatExceptionOfType (UnrenderableWhereClauseException .class ).isThrownBy (() ->
72
- deleteFrom (person )
73
- .where ()
74
- .build ()
75
- .render (RenderingStrategies .MYBATIS3 )
78
+ deleteModel .render (RenderingStrategies .MYBATIS3 )
76
79
);
77
80
}
78
81
@@ -84,8 +87,7 @@ void testDeleteWhereCalledButNoCriteriaRequiresConfiguration() {
84
87
.build ()
85
88
.render (RenderingStrategies .MYBATIS3 );
86
89
87
- assertThat (deleteStatement .getDeleteStatement ())
88
- .isEqualTo ("delete from Person" );
90
+ assertThat (deleteStatement .getDeleteStatement ()).isEqualTo ("delete from Person" );
89
91
}
90
92
91
93
@ Test
@@ -94,18 +96,18 @@ void testDeleteWhereNotCalledIsOK() {
94
96
.build ()
95
97
.render (RenderingStrategies .MYBATIS3 );
96
98
97
- assertThat (deleteStatement .getDeleteStatement ())
98
- .isEqualTo ("delete from Person" );
99
+ assertThat (deleteStatement .getDeleteStatement ()).isEqualTo ("delete from Person" );
99
100
}
100
101
101
102
@ Test
102
103
void testSelectWhereCalledButNoCriteriaThrowsException () {
104
+ SelectModel selectModel = select (id , firstName , lastName )
105
+ .from (person )
106
+ .where ()
107
+ .build ();
108
+
103
109
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 )
109
111
);
110
112
}
111
113
@@ -135,12 +137,13 @@ void testSelectWhereNotCalledIsOK() {
135
137
136
138
@ Test
137
139
void testUpdateWhereCalledButNoCriteriaThrowsException () {
140
+ UpdateModel updateModel = update (person )
141
+ .set (id ).equalTo (1 )
142
+ .where ()
143
+ .build ();
144
+
138
145
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 )
144
147
);
145
148
}
146
149
0 commit comments