16
16
17
17
import static junit .framework .Assert .assertEquals ;
18
18
19
+ import com .google .api .generator .testutils .LineFormatter ;
19
20
import java .util .Arrays ;
20
21
import java .util .List ;
21
22
import org .junit .Test ;
@@ -42,15 +43,16 @@ public void createJavaDocComment_specialCharacter() {
42
43
.setThrows ("Exception" , "This is an exception." )
43
44
.build ();
44
45
String expected =
45
- "Service comment may include special characters: \\ \\ \\ t\\ b\\ r"
46
- + "&\" \\ f\n "
47
- + "`'{@literal @}*/\n "
48
- + "<p> title: GetBigBook: <War and Peace>\n "
49
- + "<pre>{@code\n "
50
- + "ApiFuture<Shelf> future ="
51
- + " libraryClient.createShelfCallable().futureCall(request);\n "
52
- + "}</pre>\n "
53
- + "@throws Exception This is an exception." ;
46
+ LineFormatter .lines (
47
+ "Service comment may include special characters: \\ \\ \\ t\\ b\\ r" ,
48
+ "&\" \\ f\n " ,
49
+ "`'{@literal @}*/\n " ,
50
+ "<p> title: GetBigBook: <War and Peace>\n " ,
51
+ "<pre>{@code\n " ,
52
+ "ApiFuture<Shelf> future =" ,
53
+ " libraryClient.createShelfCallable().futureCall(request);\n " ,
54
+ "}</pre>\n " ,
55
+ "@throws Exception This is an exception." );
54
56
assertEquals (expected , javaDocComment .comment ());
55
57
}
56
58
@@ -61,25 +63,28 @@ public void createJavaDocComment_sampleCode() {
61
63
JavaDocComment javaDocComment =
62
64
JavaDocComment .builder ().addComment (comment ).addSampleCode (sampleCode ).build ();
63
65
String expected =
64
- "sample codes:\n "
65
- + "<pre>{@code\n "
66
- + "resource = project/{project}/shelfId/{shelfId}\n "
67
- + "}</pre>" ;
66
+ LineFormatter .lines (
67
+ "sample codes:\n " ,
68
+ "<pre>{@code\n " ,
69
+ "resource = project/{project}/shelfId/{shelfId}\n " ,
70
+ "}</pre>" );
68
71
assertEquals (expected , javaDocComment .comment ());
69
72
}
70
73
71
74
@ Test
72
75
public void createJavaDocComment_sampleCodePreserveIndentAndLineBreaks () {
73
76
String comment = "sample codes:" ;
74
77
String formattedSampleCode =
75
- "SubscriptionAdminSettings subscriptionAdminSettings =\n "
76
- + " SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();\n " ;
78
+ LineFormatter .lines (
79
+ "SubscriptionAdminSettings subscriptionAdminSettings =\n " ,
80
+ " SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();\n " );
77
81
String badFormattingSampleCode =
78
- "SubscriptionAdminSettings subscriptionAdminSettings =\n "
79
- + " SubscriptionAdminSettings\n "
80
- + " .newBuilder()\n "
81
- + " .setEndpoint(myEndpoint)\n "
82
- + " .build();\n " ;
82
+ LineFormatter .lines (
83
+ "SubscriptionAdminSettings subscriptionAdminSettings =\n " ,
84
+ " SubscriptionAdminSettings\n " ,
85
+ " .newBuilder()\n " ,
86
+ " .setEndpoint(myEndpoint)\n " ,
87
+ " .build();\n " );
83
88
JavaDocComment formattedJavaDoc =
84
89
JavaDocComment .builder ().addComment (comment ).addSampleCode (formattedSampleCode ).build ();
85
90
JavaDocComment badFormatJavaDoc =
@@ -109,19 +114,20 @@ public void createJavaDocComment_multipleComments() {
109
114
.addOrderedList (list )
110
115
.build ();
111
116
String expected =
112
- "This is a test comment.\n "
113
- + "This is an unordered list.\n "
114
- + "<ul>\n "
115
- + "<li> A flattened method.\n "
116
- + "<li> A request object method.\n "
117
- + "<li> A callable method.\n "
118
- + "</ul>\n "
119
- + "This is an ordered list.\n "
120
- + "<ol>\n "
121
- + "<li> A flattened method.\n "
122
- + "<li> A request object method.\n "
123
- + "<li> A callable method.\n "
124
- + "</ol>" ;
117
+ LineFormatter .lines (
118
+ "This is a test comment.\n " ,
119
+ "This is an unordered list.\n " ,
120
+ "<ul>\n " ,
121
+ "<li> A flattened method.\n " ,
122
+ "<li> A request object method.\n " ,
123
+ "<li> A callable method.\n " ,
124
+ "</ul>\n " ,
125
+ "This is an ordered list.\n " ,
126
+ "<ol>\n " ,
127
+ "<li> A flattened method.\n " ,
128
+ "<li> A request object method.\n " ,
129
+ "<li> A callable method.\n " ,
130
+ "</ol>" );
125
131
assertEquals (expected , javaDocComment .comment ());
126
132
}
127
133
@@ -166,8 +172,9 @@ public void createJavaDocComment_throwsAndDeprecated() {
166
172
.setDeprecated (deprecatedText_print )
167
173
.build ();
168
174
String expected =
169
- "@throws java.lang.RuntimeException if the remote call fails.\n "
170
- + "@deprecated Use the {@link ShelfBookName} class instead." ;
175
+ LineFormatter .lines (
176
+ "@throws java.lang.RuntimeException if the remote call fails.\n " ,
177
+ "@deprecated Use the {@link ShelfBookName} class instead." );
171
178
assertEquals (expected , javaDocComment .comment ());
172
179
}
173
180
@@ -205,24 +212,21 @@ public void createJavaDocComment_allComponents() {
205
212
.addParam (paramName2 , paramDescription2 )
206
213
.build ();
207
214
String expected =
208
- "this is a test comment\n "
209
- + "<p> This class provides the ability to make remote calls to the backing service"
210
- + " through method calls that map to API methods. Sample code to get started:\n "
211
- + "<p> The surface of this class includes several types of Java methods for each of"
212
- + " the API's methods:\n "
213
- + "<ol>\n "
214
- + "<li> A flattened method.\n "
215
- + "<li> A request object method.\n "
216
- + "<li> A callable method.\n "
217
- + "</ol>\n "
218
- + "@param shelfName The name of the shelf where books are published to.\n "
219
- + "@param shelf The shelf to create.\n "
220
- + "@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n "
221
- + "@deprecated Use the {@link ArchivedBookName} class instead." ;
215
+ LineFormatter .lines (
216
+ "this is a test comment\n " ,
217
+ "<p> This class provides the ability to make remote calls to the backing service"
218
+ + " through method calls that map to API methods. Sample code to get started:\n " ,
219
+ "<p> The surface of this class includes several types of Java methods for each of"
220
+ + " the API's methods:\n " ,
221
+ "<ol>\n " ,
222
+ "<li> A flattened method.\n " ,
223
+ "<li> A request object method.\n " ,
224
+ "<li> A callable method.\n " ,
225
+ "</ol>\n " ,
226
+ "@param shelfName The name of the shelf where books are published to.\n " ,
227
+ "@param shelf The shelf to create.\n " ,
228
+ "@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n " ,
229
+ "@deprecated Use the {@link ArchivedBookName} class instead." );
222
230
assertEquals (expected , javaDocComment .comment ());
223
231
}
224
-
225
- private static String createLines (int numLines ) {
226
- return new String (new char [numLines ]).replace ("\0 " , "%s" );
227
- }
228
232
}
0 commit comments