aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorShaishav Gandhi <shaishgandhi@gmail.com>2018-10-03 19:59:30 -0700
committerJesse Wilson <jesse@swank.ca>2018-10-03 22:59:30 -0400
commitea7a02ee88f8a3aa9afd3a9268390f4f9fee4b59 (patch)
tree765d380c3383e3f8b49398eec2b75a819f7219eb /src/test
parentc93bfa88c30940d4f9bda88cac322ebbb83703a6 (diff)
downloadjavapoet-ea7a02ee88f8a3aa9afd3a9268390f4f9fee4b59.tar.gz
Add Javadoc to ParameterSpec (#676)
* Add Javadoc to ParameterSpec Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com> * Move emission to same CodeBlock Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com> * Remove eager javadoc addition and fallback to adding doc when emitting Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com> * Fix formatting Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com> * Add new line before emitting parameter javadoc Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com> * Emit new line before @param only if method javadoc is present Signed-off-by: shaishavgandhi05 <shaishgandhi@gmail.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/squareup/javapoet/MethodSpecTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/java/com/squareup/javapoet/MethodSpecTest.java b/src/test/java/com/squareup/javapoet/MethodSpecTest.java
index 5dfabaa..c6e05c6 100644
--- a/src/test/java/com/squareup/javapoet/MethodSpecTest.java
+++ b/src/test/java/com/squareup/javapoet/MethodSpecTest.java
@@ -270,6 +270,59 @@ public final class MethodSpecTest {
assertThat(a.hashCode()).isEqualTo(b.hashCode());
}
+ @Test public void withoutParameterJavaDoc() {
+ MethodSpec methodSpec = MethodSpec.methodBuilder("getTaco")
+ .addModifiers(Modifier.PRIVATE)
+ .addParameter(TypeName.DOUBLE, "money")
+ .addJavadoc("Gets the best Taco\n")
+ .build();
+ assertThat(methodSpec.toString()).isEqualTo(""
+ + "/**\n"
+ + " * Gets the best Taco\n"
+ + " */\n"
+ + "private void getTaco(double money) {\n"
+ + "}\n");
+ }
+
+ @Test public void withParameterJavaDoc() {
+ MethodSpec methodSpec = MethodSpec.methodBuilder("getTaco")
+ .addParameter(ParameterSpec.builder(TypeName.DOUBLE, "money")
+ .addJavadoc("the amount required to buy the taco.\n")
+ .build())
+ .addParameter(ParameterSpec.builder(TypeName.INT, "count")
+ .addJavadoc("the number of Tacos to buy.\n")
+ .build())
+ .addJavadoc("Gets the best Taco money can buy.\n")
+ .build();
+ assertThat(methodSpec.toString()).isEqualTo(""
+ + "/**\n"
+ + " * Gets the best Taco money can buy.\n"
+ + " *\n"
+ + " * @param money the amount required to buy the taco.\n"
+ + " * @param count the number of Tacos to buy.\n"
+ + " */\n"
+ + "void getTaco(double money, int count) {\n"
+ + "}\n");
+ }
+
+ @Test public void withParameterJavaDocAndWithoutMethodJavadoc() {
+ MethodSpec methodSpec = MethodSpec.methodBuilder("getTaco")
+ .addParameter(ParameterSpec.builder(TypeName.DOUBLE, "money")
+ .addJavadoc("the amount required to buy the taco.\n")
+ .build())
+ .addParameter(ParameterSpec.builder(TypeName.INT, "count")
+ .addJavadoc("the number of Tacos to buy.\n")
+ .build())
+ .build();
+ assertThat(methodSpec.toString()).isEqualTo(""
+ + "/**\n"
+ + " * @param money the amount required to buy the taco.\n"
+ + " * @param count the number of Tacos to buy.\n"
+ + " */\n"
+ + "void getTaco(double money, int count) {\n"
+ + "}\n");
+ }
+
@Test public void duplicateExceptionsIgnored() {
ClassName ioException = ClassName.get(IOException.class);
ClassName timeoutException = ClassName.get(TimeoutException.class);