1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.renderkit.css;
21
22 import org.junit.jupiter.api.Assertions;
23 import org.junit.jupiter.api.Test;
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 public class TobagoClassUnitTest {
30
31 @Test
32 public void testNames() throws NoSuchFieldException {
33
34 final String fieldRegex = "[A-Z_]*[A-Z]";
35 final String nameRegex = "[a-z][a-zA-Z\\-]*[a-z]";
36
37 for (final TobagoClass value : TobagoClass.values()) {
38 final boolean ignoreByTest = TobagoClass.class.getField(value.name()).isAnnotationPresent(Deprecated.class);
39 if (!ignoreByTest) {
40 final String field = value.toString();
41 final String name = value.getName();
42
43 Assertions.assertTrue(field.matches(fieldRegex));
44 Assertions.assertTrue(name.matches(nameRegex));
45
46 final StringBuilder calculatedName = new StringBuilder();
47 calculatedName.append("tobago-");
48 for (int i = 0; i < field.length(); i++) {
49 final char c = field.charAt(i);
50 if (c == '_') {
51 final char nextChar = field.charAt(i + 1);
52 if (nextChar == '_') {
53 calculatedName.append("-");
54 } else {
55 calculatedName.append(nextChar);
56 }
57 i++;
58 } else {
59 calculatedName.append(Character.toLowerCase(c));
60 }
61 }
62
63 Assertions.assertEquals(calculatedName.toString(), name, field);
64 }
65 }
66 }
67
68
69
70
71 @Test
72 public void testCompareTobagoCss() throws IOException, NoSuchFieldException {
73
74 final TobagoClass[] allValues = TobagoClass.values();
75 final List<TobagoClass> toCheck = new ArrayList<>();
76 for (final TobagoClass value : allValues) {
77 final boolean ignoreByTest = TobagoClass.class.getField(value.name()).isAnnotationPresent(Deprecated.class);
78 if (!ignoreByTest) {
79 toCheck.add(value);
80 }
81 }
82
83 final List<CssItem> missing =
84 CssClassUtils.compareCss("npm/scss/_tobago.scss",
85 toCheck.toArray(new CssItem[0]));
86
87 Assertions.assertTrue(missing.isEmpty(), "These classes are missing in _tobago.scss: " + missing);
88 }
89
90 }