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;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  
24  import java.io.IOException;
25  import java.util.Arrays;
26  import java.util.Objects;
27  import java.util.Set;
28  import java.util.stream.Collectors;
29  import java.util.stream.Stream;
30  
31  import org.junit.jupiter.api.Test;
32  
33  import com.puppycrawl.tools.checkstyle.checks.header.AbstractHeaderCheck;
34  import com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil;
35  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
36  
37  public class XdocsPropertyTypeTest {
38  
39      @Test
40      public void testAllPropertyTypesAreUsed() throws IOException {
41          final Set<PropertyType> propertyTypes = Stream.concat(
42                  Stream.of(AbstractHeaderCheck.class, Checker.class),
43                  CheckUtil.getCheckstyleChecks().stream())
44              .map(Class::getDeclaredFields)
45              .flatMap(Arrays::stream)
46              .map(field -> field.getAnnotation(XdocsPropertyType.class))
47              .filter(Objects::nonNull)
48              .map(XdocsPropertyType::value)
49              .collect(Collectors.toUnmodifiableSet());
50  
51          assertWithMessage("All property types should be used")
52              .that(propertyTypes)
53              .containsExactlyElementsIn(PropertyType.values());
54      }
55  
56      @Test
57      public void testAllPropertyTypesHaveDescription() {
58          for (PropertyType value : PropertyType.values()) {
59              assertWithMessage("Property type '%s' has no description", value)
60                  .that(CommonUtil.isBlank(value.getDescription()))
61                  .isFalse();
62          }
63      }
64  
65  }