Skip to content

Commit

Permalink
[ggj][engx] fix: centralize/streamline createLines() test util (#510)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
miraleung authored Nov 18, 2020
1 parent 503ab4c commit 3550fe5
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ filegroup(
test_class = "com.google.api.generator.engine.ast.{0}".format(test_name),
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/test/java/com/google/api/generator/testutils",
"@com_google_guava_guava//jar",
"@com_google_truth_truth//jar",
"@junit_junit//jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static junit.framework.Assert.assertEquals;

import com.google.api.generator.testutils.LineFormatter;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
Expand All @@ -42,15 +43,16 @@ public void createJavaDocComment_specialCharacter() {
.setThrows("Exception", "This is an exception.")
.build();
String expected =
"Service comment may include special characters: \\\\ \\t\\b\\r"
+ "&\"\\f\n"
+ "`'{@literal @}*/\n"
+ "<p> title: GetBigBook: &lt;War and Peace&gt;\n"
+ "<pre>{@code\n"
+ "ApiFuture<Shelf> future ="
+ " libraryClient.createShelfCallable().futureCall(request);\n"
+ "}</pre>\n"
+ "@throws Exception This is an exception.";
LineFormatter.lines(
"Service comment may include special characters: \\\\ \\t\\b\\r",
"&amp;\"\\f\n",
"`'{@literal @}&#42;/\n",
"<p> title: GetBigBook: &lt;War and Peace&gt;\n",
"<pre>{@code\n",
"ApiFuture<Shelf> future =",
" libraryClient.createShelfCallable().futureCall(request);\n",
"}</pre>\n",
"@throws Exception This is an exception.");
assertEquals(expected, javaDocComment.comment());
}

Expand All @@ -61,25 +63,28 @@ public void createJavaDocComment_sampleCode() {
JavaDocComment javaDocComment =
JavaDocComment.builder().addComment(comment).addSampleCode(sampleCode).build();
String expected =
"sample codes:\n"
+ "<pre>{@code\n"
+ "resource = project/{project}/shelfId/{shelfId}\n"
+ "}</pre>";
LineFormatter.lines(
"sample codes:\n",
"<pre>{@code\n",
"resource = project/{project}/shelfId/{shelfId}\n",
"}</pre>");
assertEquals(expected, javaDocComment.comment());
}

@Test
public void createJavaDocComment_sampleCodePreserveIndentAndLineBreaks() {
String comment = "sample codes:";
String formattedSampleCode =
"SubscriptionAdminSettings subscriptionAdminSettings =\n"
+ " SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();\n";
LineFormatter.lines(
"SubscriptionAdminSettings subscriptionAdminSettings =\n",
" SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();\n");
String badFormattingSampleCode =
"SubscriptionAdminSettings subscriptionAdminSettings =\n"
+ " SubscriptionAdminSettings\n"
+ " .newBuilder()\n"
+ " .setEndpoint(myEndpoint)\n"
+ " .build();\n";
LineFormatter.lines(
"SubscriptionAdminSettings subscriptionAdminSettings =\n",
" SubscriptionAdminSettings\n",
" .newBuilder()\n",
" .setEndpoint(myEndpoint)\n",
" .build();\n");
JavaDocComment formattedJavaDoc =
JavaDocComment.builder().addComment(comment).addSampleCode(formattedSampleCode).build();
JavaDocComment badFormatJavaDoc =
Expand Down Expand Up @@ -109,19 +114,20 @@ public void createJavaDocComment_multipleComments() {
.addOrderedList(list)
.build();
String expected =
"This is a test comment.\n"
+ "This is an unordered list.\n"
+ "<ul>\n"
+ "<li> A flattened method.\n"
+ "<li> A request object method.\n"
+ "<li> A callable method.\n"
+ "</ul>\n"
+ "This is an ordered list.\n"
+ "<ol>\n"
+ "<li> A flattened method.\n"
+ "<li> A request object method.\n"
+ "<li> A callable method.\n"
+ "</ol>";
LineFormatter.lines(
"This is a test comment.\n",
"This is an unordered list.\n",
"<ul>\n",
"<li> A flattened method.\n",
"<li> A request object method.\n",
"<li> A callable method.\n",
"</ul>\n",
"This is an ordered list.\n",
"<ol>\n",
"<li> A flattened method.\n",
"<li> A request object method.\n",
"<li> A callable method.\n",
"</ol>");
assertEquals(expected, javaDocComment.comment());
}

Expand Down Expand Up @@ -166,8 +172,9 @@ public void createJavaDocComment_throwsAndDeprecated() {
.setDeprecated(deprecatedText_print)
.build();
String expected =
"@throws java.lang.RuntimeException if the remote call fails.\n"
+ "@deprecated Use the {@link ShelfBookName} class instead.";
LineFormatter.lines(
"@throws java.lang.RuntimeException if the remote call fails.\n",
"@deprecated Use the {@link ShelfBookName} class instead.");
assertEquals(expected, javaDocComment.comment());
}

Expand Down Expand Up @@ -205,24 +212,21 @@ public void createJavaDocComment_allComponents() {
.addParam(paramName2, paramDescription2)
.build();
String expected =
"this is a test comment\n"
+ "<p> This class provides the ability to make remote calls to the backing service"
+ " through method calls that map to API methods. Sample code to get started:\n"
+ "<p> The surface of this class includes several types of Java methods for each of"
+ " the API's methods:\n"
+ "<ol>\n"
+ "<li> A flattened method.\n"
+ "<li> A request object method.\n"
+ "<li> A callable method.\n"
+ "</ol>\n"
+ "@param shelfName The name of the shelf where books are published to.\n"
+ "@param shelf The shelf to create.\n"
+ "@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n"
+ "@deprecated Use the {@link ArchivedBookName} class instead.";
LineFormatter.lines(
"this is a test comment\n",
"<p> This class provides the ability to make remote calls to the backing service"
+ " through method calls that map to API methods. Sample code to get started:\n",
"<p> The surface of this class includes several types of Java methods for each of"
+ " the API's methods:\n",
"<ol>\n",
"<li> A flattened method.\n",
"<li> A request object method.\n",
"<li> A callable method.\n",
"</ol>\n",
"@param shelfName The name of the shelf where books are published to.\n",
"@param shelf The shelf to create.\n",
"@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n",
"@deprecated Use the {@link ArchivedBookName} class instead.");
assertEquals(expected, javaDocComment.comment());
}

private static String createLines(int numLines) {
return new String(new char[numLines]).replace("\0", "%s");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ filegroup(
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/engine/writer",
"//src/test/java/com/google/api/generator/testutils",
"@com_google_guava_guava//jar",
"@com_google_truth_truth//jar",
"@junit_junit//jar",
Expand Down
Loading

0 comments on commit 3550fe5

Please sign in to comment.