View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.checks.javadoc;
21  
22  import static com.google.common.truth.Truth.assertThat;
23  import static com.google.common.truth.Truth.assertWithMessage;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
28  
29  public class JavadocTagTest {
30  
31      /* Additional test for jacoco, since valueOf()
32       * is generated by javac and jacoco reports that
33       * valueOf() is uncovered.
34       */
35      @Test
36      public void testJavadocTagTypeValueOf() {
37          final JavadocUtil.JavadocTagType enumConst =
38              JavadocUtil.JavadocTagType.valueOf("ALL");
39          assertWithMessage("Invalid enum valueOf result")
40              .that(enumConst)
41              .isEqualTo(JavadocUtil.JavadocTagType.ALL);
42      }
43  
44      /* Additional test for jacoco, since values()
45       * is generated by javac and jacoco reports that
46       * values() is uncovered.
47       */
48      @Test
49      public void testJavadocTagTypeValues() {
50          final JavadocUtil.JavadocTagType[] enumConstants =
51              JavadocUtil.JavadocTagType.values();
52          final JavadocUtil.JavadocTagType[] expected = {
53              JavadocUtil.JavadocTagType.BLOCK,
54              JavadocUtil.JavadocTagType.INLINE,
55              JavadocUtil.JavadocTagType.ALL,
56          };
57          assertWithMessage("Invalid enum constants")
58              .that(enumConstants)
59              .isEqualTo(expected);
60      }
61  
62      @Test
63      public void testToString() {
64          final JavadocTag javadocTag = new JavadocTag(0, 1, "author", "firstArg");
65  
66          final String result = javadocTag.toString();
67  
68          assertWithMessage("Invalid toString result")
69              .that(result)
70              .isEqualTo("JavadocTag[tag='author' lineNo=0, columnNo=1, firstArg='firstArg']");
71      }
72  
73      @Test
74      public void testJavadocTagReferenceImports() {
75          assertThat(new JavadocTag(0, 0, "see", null).canReferenceImports()).isTrue();
76          assertThat(new JavadocTag(0, 0, "link", null).canReferenceImports()).isTrue();
77          assertThat(new JavadocTag(0, 0, "value", null).canReferenceImports()).isTrue();
78          assertThat(new JavadocTag(0, 0, "linkplain", null).canReferenceImports()).isTrue();
79          assertThat(new JavadocTag(0, 0, "throws", null).canReferenceImports()).isTrue();
80          assertThat(new JavadocTag(0, 0, "exception", null).canReferenceImports()).isTrue();
81      }
82  
83      @Test
84      public void testJavadocTagReferenceImportsInvalid() {
85          assertThat(new JavadocTag(0, 0, "author", null).canReferenceImports())
86                  .isFalse();
87      }
88  
89  }