22
22
import org .junit .Test ;
23
23
24
24
public class JavaDocCommentTest {
25
+ @ Test
26
+ public void emptyJavaDocComment () {
27
+ JavaDocComment .Builder javaDocCommentBuilder = JavaDocComment .builder ();
28
+ assertEquals (true , javaDocCommentBuilder .emptyComments ());
29
+
30
+ String content = "testing return" ;
31
+ javaDocCommentBuilder .setReturn (content );
32
+ assertEquals (false , javaDocCommentBuilder .emptyComments ());
33
+ }
34
+
25
35
@ Test
26
36
public void createJavaDocComment_basic () {
27
37
String content = "this is a test comment" ;
@@ -153,9 +163,34 @@ public void createJavaDocComment_multipleParams() {
153
163
}
154
164
155
165
@ Test
156
- public void createJavaDocComment_throwsAndDeprecated () {
157
- // No matter how many times or order `setThrows` and `setDeprecated` are called,
158
- // only one @throws and @deprecated will be printed.
166
+ public void createJavaDocComment_multipleParamsAndReturn () {
167
+ // Parameters should be grouped together and get printed after block comments.
168
+ // Return text should get printed at the very end.
169
+ String comment = "This is a block comment." ;
170
+ String paramName1 = "shelfName" ;
171
+ String paramDescription1 = "The name of the shelf where books are published to." ;
172
+ String paramName2 = "shelfId" ;
173
+ String paramDescription2 = "The shelfId of the shelf where books are published to." ;
174
+ String returnText = "This is the method return text." ;
175
+ JavaDocComment javaDocComment =
176
+ JavaDocComment .builder ()
177
+ .addParam (paramName1 , paramDescription1 )
178
+ .addParam (paramName2 , paramDescription2 )
179
+ .addComment (comment )
180
+ .setReturn (returnText )
181
+ .build ();
182
+ String expected =
183
+ "This is a block comment.\n "
184
+ + "@param shelfName The name of the shelf where books are published to.\n "
185
+ + "@param shelfId The shelfId of the shelf where books are published to.\n "
186
+ + "@return This is the method return text." ;
187
+ assertEquals (expected , javaDocComment .comment ());
188
+ }
189
+
190
+ @ Test
191
+ public void createJavaDocComment_throwsAndDeprecatedAndReturn () {
192
+ // No matter how many times or order `setThrows`, `setDeprecated`, `setReturn` are called,
193
+ // only one @throws, @deprecated, and @return will be printed.
159
194
String throwsType = "com.google.api.gax.rpc.ApiException" ;
160
195
String throwsDescription = "if the remote call fails." ;
161
196
String throwsType_print = "java.lang.RuntimeException" ;
@@ -164,28 +199,35 @@ public void createJavaDocComment_throwsAndDeprecated() {
164
199
String deprecatedText = "Use the {@link ArchivedBookName} class instead." ;
165
200
String deprecatedText_print = "Use the {@link ShelfBookName} class instead." ;
166
201
202
+ String returnText = "This is the incorrect method return text." ;
203
+ String returnText_print = "This is the correct method return text." ;
204
+
167
205
JavaDocComment javaDocComment =
168
206
JavaDocComment .builder ()
169
207
.setThrows (throwsType , throwsDescription )
170
208
.setDeprecated (deprecatedText )
209
+ .setReturn (returnText )
171
210
.setThrows (throwsType_print , throwsDescription_print )
172
211
.setDeprecated (deprecatedText_print )
212
+ .setReturn (returnText_print )
173
213
.build ();
174
214
String expected =
175
215
LineFormatter .lines (
176
216
"@throws java.lang.RuntimeException if the remote call fails.\n " ,
177
- "@deprecated Use the {@link ShelfBookName} class instead." );
217
+ "@deprecated Use the {@link ShelfBookName} class instead.\n " ,
218
+ "@return This is the correct method return text." );
178
219
assertEquals (expected , javaDocComment .comment ());
179
220
}
180
221
181
222
@ Test
182
223
public void createJavaDocComment_allComponents () {
183
- // No matter what order `setThrows`, `setDeprecated` are called,
224
+ // No matter what order `setThrows`, `setDeprecated`, and `setReturn` are called,
184
225
// They will be printed at the end. And `@param` should be grouped,
185
- // they should always be printed right before `@throws` and `@deprecated `.
226
+ // they should always be printed right before `@throws`, `@deprecated`, and `@return `.
186
227
// All other add methods should keep the order of how they are added.
187
228
String content = "this is a test comment" ;
188
229
String deprecatedText = "Use the {@link ArchivedBookName} class instead." ;
230
+ String returnText = "This is the method return text." ;
189
231
String paramName1 = "shelfName" ;
190
232
String paramDescription1 = "The name of the shelf where books are published to." ;
191
233
String paramName2 = "shelf" ;
@@ -204,6 +246,7 @@ public void createJavaDocComment_allComponents() {
204
246
JavaDocComment .builder ()
205
247
.setDeprecated (deprecatedText )
206
248
.setThrows (throwsType , throwsDescription )
249
+ .setReturn (returnText )
207
250
.addParam (paramName1 , paramDescription1 )
208
251
.addComment (content )
209
252
.addParagraph (paragraph1 )
@@ -226,7 +269,8 @@ public void createJavaDocComment_allComponents() {
226
269
"@param shelfName The name of the shelf where books are published to.\n " ,
227
270
"@param shelf The shelf to create.\n " ,
228
271
"@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n " ,
229
- "@deprecated Use the {@link ArchivedBookName} class instead." );
272
+ "@deprecated Use the {@link ArchivedBookName} class instead.\n " ,
273
+ "@return This is the method return text." );
230
274
assertEquals (expected , javaDocComment .comment ());
231
275
}
232
276
}
0 commit comments