1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.javadoc.utils;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.List;
26
27 import org.junit.Test;
28
29 import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
30
31 public class BlockTagUtilTest {
32
33 @Test
34 public void testHasPrivateConstructor() throws Exception {
35 assertTrue("Constructor is not private",
36 TestUtil.isUtilsClassHasPrivateConstructor(BlockTagUtil.class, true));
37 }
38
39 @Test
40 public void testExtractBlockTags() {
41 final String[] text = {
42 "/** @foo abc ",
43 " * @bar def ",
44 " @baz ghi ",
45 " * @qux jkl",
46 " */",
47 };
48
49 final List<TagInfo> tags = BlockTagUtil.extractBlockTags(text);
50 assertEquals("Invalid tags size", 4, tags.size());
51
52 final TagInfo tag1 = tags.get(0);
53 assertTagEquals(tag1, "foo", "abc", 1, 4);
54
55 final TagInfo tag2 = tags.get(1);
56 assertTagEquals(tag2, "bar", "def", 2, 3);
57
58 final TagInfo tag3 = tags.get(2);
59 assertTagEquals(tag3, "baz", "ghi", 3, 3);
60
61 final TagInfo tag4 = tags.get(3);
62 assertTagEquals(tag4, "qux", "jkl", 4, 3);
63 }
64
65 @Test
66 public void testVersionStringFormat() {
67 final String[] text = {
68 "/** ",
69 " * @version 1.0",
70 " */",
71 };
72 final List<TagInfo> tags = BlockTagUtil.extractBlockTags(text);
73 assertEquals("Invalid tags size", 1, tags.size());
74 assertEquals("Invalid tag name", "version", tags.get(0).getName());
75 assertEquals("Invalid tag value", "1.0", tags.get(0).getValue());
76 }
77
78 @Test
79 public void testOddVersionString() {
80 final String[] text = {
81 "/**",
82 " * Foo",
83 " * @version 1.0 */"};
84
85 final List<TagInfo> tags = BlockTagUtil.extractBlockTags(text);
86 assertEquals("Invalid tags size", 1, tags.size());
87 assertEquals("Invalid tag name", "version", tags.get(0).getName());
88 assertEquals("Invalid tag value", "1.0", tags.get(0).getValue());
89 }
90
91 private static void assertTagEquals(TagInfo tag, String name, String value,
92 int line, int column) {
93 assertEquals("Invalid tag name", name, tag.getName());
94 assertEquals("Invalid tag value", value, tag.getValue());
95 assertEquals("Invalid tag line", line, tag.getPosition().getLine());
96 assertEquals("Invalid tag column", column, tag.getPosition().getColumn());
97 }
98
99 }