Skip to content

Commit 3550fe5

Browse files
authored
[ggj][engx] fix: centralize/streamline createLines() test util (#510)
* fix: Update LRO initial_retry_delayo o 5s (discussion in doc) * fix: correct some common typos * fix: switch assertEquals (actual,expected) args order in JavaDocCommentTest * fix: switch assertEquals (actual,expected) args order in AST tests * fix: switch assertEquals (actual,expected) args order in gapic tests * fix: merge master * fix: centralize/streamline createLines() test util
1 parent 503ab4c commit 3550fe5

11 files changed

+167
-424
lines changed

src/test/java/com/google/api/generator/engine/ast/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ filegroup(
5454
test_class = "com.google.api.generator.engine.ast.{0}".format(test_name),
5555
deps = [
5656
"//src/main/java/com/google/api/generator/engine/ast",
57+
"//src/test/java/com/google/api/generator/testutils",
5758
"@com_google_guava_guava//jar",
5859
"@com_google_truth_truth//jar",
5960
"@junit_junit//jar",

src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java

+57-53
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static junit.framework.Assert.assertEquals;
1818

19+
import com.google.api.generator.testutils.LineFormatter;
1920
import java.util.Arrays;
2021
import java.util.List;
2122
import org.junit.Test;
@@ -42,15 +43,16 @@ public void createJavaDocComment_specialCharacter() {
4243
.setThrows("Exception", "This is an exception.")
4344
.build();
4445
String expected =
45-
"Service comment may include special characters: \\\\ \\t\\b\\r"
46-
+ "&\"\\f\n"
47-
+ "`'{@literal @}*/\n"
48-
+ "<p> title: GetBigBook: &lt;War and Peace&gt;\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+
"&amp;\"\\f\n",
49+
"`'{@literal @}&#42;/\n",
50+
"<p> title: GetBigBook: &lt;War and Peace&gt;\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.");
5456
assertEquals(expected, javaDocComment.comment());
5557
}
5658

@@ -61,25 +63,28 @@ public void createJavaDocComment_sampleCode() {
6163
JavaDocComment javaDocComment =
6264
JavaDocComment.builder().addComment(comment).addSampleCode(sampleCode).build();
6365
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>");
6871
assertEquals(expected, javaDocComment.comment());
6972
}
7073

7174
@Test
7275
public void createJavaDocComment_sampleCodePreserveIndentAndLineBreaks() {
7376
String comment = "sample codes:";
7477
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");
7781
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");
8388
JavaDocComment formattedJavaDoc =
8489
JavaDocComment.builder().addComment(comment).addSampleCode(formattedSampleCode).build();
8590
JavaDocComment badFormatJavaDoc =
@@ -109,19 +114,20 @@ public void createJavaDocComment_multipleComments() {
109114
.addOrderedList(list)
110115
.build();
111116
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>");
125131
assertEquals(expected, javaDocComment.comment());
126132
}
127133

@@ -166,8 +172,9 @@ public void createJavaDocComment_throwsAndDeprecated() {
166172
.setDeprecated(deprecatedText_print)
167173
.build();
168174
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.");
171178
assertEquals(expected, javaDocComment.comment());
172179
}
173180

@@ -205,24 +212,21 @@ public void createJavaDocComment_allComponents() {
205212
.addParam(paramName2, paramDescription2)
206213
.build();
207214
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.");
222230
assertEquals(expected, javaDocComment.comment());
223231
}
224-
225-
private static String createLines(int numLines) {
226-
return new String(new char[numLines]).replace("\0", "%s");
227-
}
228232
}

src/test/java/com/google/api/generator/engine/writer/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ filegroup(
1919
deps = [
2020
"//src/main/java/com/google/api/generator/engine/ast",
2121
"//src/main/java/com/google/api/generator/engine/writer",
22+
"//src/test/java/com/google/api/generator/testutils",
2223
"@com_google_guava_guava//jar",
2324
"@com_google_truth_truth//jar",
2425
"@junit_junit//jar",

0 commit comments

Comments
 (0)