View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.api.LineColumn;
28  import com.puppycrawl.tools.checkstyle.checks.javadoc.utils.TagInfo;
29  
30  public class JavadocTagTest {
31  
32      @Test
33      public void testToString() {
34          final JavadocTag javadocTag = new JavadocTag(0, 1, "author", "firstArg");
35  
36          final String result = javadocTag.toString();
37  
38          assertWithMessage("Invalid toString result")
39              .that(result)
40              .isEqualTo("JavadocTag[tag='author' lineNo=0, columnNo=1, firstArg='firstArg']");
41      }
42  
43      @Test
44      public void testJavadocTagReferenceImports() {
45          assertThat(new JavadocTag(0, 0, "see", null).canReferenceImports()).isTrue();
46          assertThat(new JavadocTag(0, 0, "link", null).canReferenceImports()).isTrue();
47          assertThat(new JavadocTag(0, 0, "value", null).canReferenceImports()).isTrue();
48          assertThat(new JavadocTag(0, 0, "linkplain", null).canReferenceImports()).isTrue();
49          assertThat(new JavadocTag(0, 0, "throws", null).canReferenceImports()).isTrue();
50          assertThat(new JavadocTag(0, 0, "exception", null).canReferenceImports()).isTrue();
51      }
52  
53      @Test
54      public void testJavadocTagReferenceImportsInvalid() {
55          assertThat(new JavadocTag(0, 0, "author", null).canReferenceImports())
56                  .isFalse();
57      }
58  
59      @Test
60      public void testJavadocTagIsInlineTag() {
61          assertThat(new JavadocTag(0, 0, "link", null).isInlineTag()).isTrue();
62          assertThat(new JavadocTag(0, 0, "value", null).isInlineTag()).isTrue();
63          assertThat(new JavadocTag(0, 0, "see", null).isInlineTag()).isFalse();
64  
65      }
66  
67      @Test
68      public void testInvalidJavadocTagLegacyGetters() {
69          final InvalidJavadocTag tag = new InvalidJavadocTag(1, 2, "test");
70          assertWithMessage("Invalid line number")
71              .that(tag.getLine())
72              .isEqualTo(1);
73          assertWithMessage("Invalid column number")
74              .that(tag.getCol())
75              .isEqualTo(2);
76          assertWithMessage("Invalid tag name")
77              .that(tag.getName())
78              .isEqualTo("test");
79          assertWithMessage("Invalid line number")
80              .that(tag.line())
81              .isEqualTo(1);
82          assertWithMessage("Invalid column number")
83              .that(tag.col())
84              .isEqualTo(2);
85          assertWithMessage("Invalid tag name")
86              .that(tag.name())
87              .isEqualTo("test");
88      }
89  
90      @Test
91      public void testTagInfoLegacyGetters() {
92          final LineColumn position = new LineColumn(1, 2);
93          final TagInfo tagInfo = new TagInfo("name", "value", position);
94          assertWithMessage("Invalid name")
95              .that(tagInfo.getName())
96              .isEqualTo("name");
97          assertWithMessage("Invalid value")
98              .that(tagInfo.getValue())
99              .isEqualTo("value");
100         assertWithMessage("Invalid position")
101             .that(tagInfo.getPosition())
102             .isEqualTo(position);
103         assertWithMessage("Invalid name")
104             .that(tagInfo.name())
105             .isEqualTo("name");
106         assertWithMessage("Invalid value")
107             .that(tagInfo.value())
108             .isEqualTo("value");
109         assertWithMessage("Invalid position")
110             .that(tagInfo.position())
111             .isEqualTo(position);
112     }
113 
114 }