-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathEmptySectionsInClassDefTest.java
272 lines (228 loc) · 8.04 KB
/
EmptySectionsInClassDefTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package com.sap.adt.abapcleaner.rules.declarations;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.sap.adt.abapcleaner.rulebase.RuleID;
import com.sap.adt.abapcleaner.rulebase.RuleTestBase;
public class EmptySectionsInClassDefTest extends RuleTestBase {
private EmptySectionsInClassDefRule rule;
EmptySectionsInClassDefTest() {
super(RuleID.EMPTY_SECTIONS);
rule = (EmptySectionsInClassDefRule)getRule();
}
@BeforeEach
void setUp() {
// setup default test configuration (may be modified in the individual test methods)
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_ANY_FROM_NON_EMPTY_CLASS);
}
@Test
void testRemoveProtectedSectionOnly() {
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_PROTECTED_OF_FINAL_CLASS);
buildSrc("CLASS cl_any_final_class DEFINITION FINAL.");
buildSrc(" PUBLIC SECTION.");
buildSrc("*\"* public components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc(" INTERFACES if_any_interface.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("*\"* protected components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("*\"* private components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc("");
buildSrc("ENDCLASS.");
buildExp("CLASS cl_any_final_class DEFINITION FINAL.");
buildExp(" PUBLIC SECTION.");
buildExp("*\"* public components of class CL_ANY_FINAL_CLASS");
buildExp("*\"* do not include other source files here!!!");
buildExp(" INTERFACES if_any_interface.");
buildExp("");
buildExp(" PRIVATE SECTION.");
buildExp("*\"* private components of class CL_ANY_FINAL_CLASS");
buildExp("*\"* do not include other source files here!!!");
buildExp("");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testKeepProtectedSectionInNonFinalClass() {
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_PROTECTED_OF_FINAL_CLASS);
buildSrc("CLASS cl_any_non_final_class DEFINITION FOR TESTING.");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc(" DATA mv_any_data TYPE i.");
buildSrc("");
buildSrc(" METHODS setup.");
buildSrc(" METHODS any_test_method FOR TESTING.");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
@Test
void testRemovEmptySectionsWithComments() {
buildSrc("CLASS cl_any_final_class DEFINITION FINAL.");
buildSrc(" PUBLIC SECTION.");
buildSrc("*\"* public components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc(" INTERFACES if_any_interface.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("*\"* protected components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("*\"* private components of class CL_ANY_FINAL_CLASS");
buildSrc("*\"* do not include other source files here!!!");
buildSrc("");
buildSrc("ENDCLASS.");
buildExp("CLASS cl_any_final_class DEFINITION FINAL.");
buildExp(" PUBLIC SECTION.");
buildExp("*\"* public components of class CL_ANY_FINAL_CLASS");
buildExp("*\"* do not include other source files here!!!");
buildExp(" INTERFACES if_any_interface.");
buildExp("");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testRemovEmptySectionsWithoutComments() {
buildSrc("CLASS cl_any_non_final_class DEFINITION FOR TESTING.");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc(" DATA mv_any_data TYPE i.");
buildSrc("");
buildSrc(" METHODS setup.");
buildSrc(" METHODS any_test_method FOR TESTING.");
buildSrc("ENDCLASS.");
buildExp("CLASS cl_any_non_final_class DEFINITION FOR TESTING.");
buildExp(" PRIVATE SECTION.");
buildExp(" DATA mv_any_data TYPE i.");
buildExp("");
buildExp(" METHODS setup.");
buildExp(" METHODS any_test_method FOR TESTING.");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testKeepEmptySectionsInEmptyClass() {
// expect the SECTIONs of the following class to be kept, since the class was probably freshly created with a template
buildSrc("CLASS cl_any_empty_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
@Test
void testRemoveEmptySectionsFromEmptyClass() {
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_ANY);
buildSrc("CLASS cl_any_empty_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("");
buildSrc("ENDCLASS.");
buildExp("CLASS cl_any_empty_class DEFINITION.");
buildExp("");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testRemoveEmptySectionsFromAlmostEmptyClass() {
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_ANY);
buildSrc("CLASS cl_any_empty_class DEFINITION.");
buildSrc(" \" comment outside the first SECTION");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("");
buildSrc("ENDCLASS.");
buildExp("CLASS cl_any_empty_class DEFINITION.");
buildExp(" \" comment outside the first SECTION");
buildExp("");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testKeepNonEmptySections() {
rule.configEmptySectionsAction.setEnumValue(EmptySectionsAction.REMOVE_ANY);
buildSrc("CLASS cl_any_empty_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc(" \" comment");
buildSrc(" PROTECTED SECTION.");
buildSrc("* asterisk comment");
buildSrc(" PRIVATE SECTION.");
buildSrc(" ##PRAGMA");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
@Test
void testPublicChildClassUnchanged() {
// ensure that from a PUBLIC child class, empty sections are NOT removed, because a syntax error comes up in ADT
// when the protected base class constructor is called in the following scenario:
// - the base class is "PUBLIC" and "CREATE PROTECTED",
// - the base class constructor has parameters,
// - the child class is "PUBLIC",
// - the child class is "CREATE PROTECTED" (explicitly or implicitly inherited) or "CREATE PRIVATE",
// - the child class misses both the PROTECTED and the PRIVATE section.
buildSrc("CLASS cl_any_child DEFINITION PUBLIC FINAL");
buildSrc(" INHERITING FROM cl_any_base.");
buildSrc("");
buildSrc(" PUBLIC SECTION.");
buildSrc(" CLASS-METHODS create RETURNING VALUE(ro_instance) TYPE REF TO cl_any_child.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc(" PRIVATE SECTION.");
buildSrc("ENDCLASS.");
buildSrc("");
buildSrc("CLASS cl_any_child IMPLEMENTATION.");
buildSrc(" METHOD create.");
buildSrc(" ro_instance = NEW #( iv_any = 1 ).");
buildSrc(" ENDMETHOD.");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
@Test
void testKeepAllSectionsInPublicNonFinalClass() {
buildSrc("CLASS cl_any_public_non_final_class DEFINITION PUBLIC.");
buildSrc(" PUBLIC SECTION.");
buildSrc(" DATA mv_any_data TYPE i.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
@Test
void testKeepAllSectionsInPublicNonFinalClass2() {
buildSrc("CLASS cl_other_public_non_final_cls DEFINITION PUBLIC.");
buildSrc(" PUBLIC SECTION.");
buildSrc("");
buildSrc(" PROTECTED SECTION.");
buildSrc("");
buildSrc(" PRIVATE SECTION.");
buildSrc(" DATA mv_any_data TYPE i.");
buildSrc("ENDCLASS.");
copyExpFromSrc();
testRule();
}
}