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.model;
21
22 import org.apache.myfaces.tobago.util.EnumUnitTest;
23 import org.junit.jupiter.api.Assertions;
24 import org.junit.jupiter.api.Test;
25
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 public class SelectableUnitTest extends EnumUnitTest {
35
36 @Test
37 public void testNames() throws IllegalAccessException, NoSuchFieldException {
38 testNames(Selectable.class);
39 }
40
41 @Test
42 public void testTypeScript() throws IOException {
43 final Path path = Paths.get("").toAbsolutePath().getParent().resolve(
44 Paths.get("tobago-theme", "tobago-theme-standard", "npm", "ts", "tobago-selectable.ts"));
45
46 final List<String> words = getWords(path);
47
48 for (Selectable selectable : Selectable.values()) {
49 Assertions.assertTrue(words.contains(selectable.name()),
50 selectable.name() + " should be found in tobago-selectable.ts");
51 }
52 }
53
54 private List<String> getWords(final Path path) throws IOException {
55 List<String> words = new ArrayList<>();
56
57 final String fileContent = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
58
59
60 StringBuilder stringBuilder = new StringBuilder();
61
62 for (char c : fileContent.toCharArray()) {
63 if (('0' <= c && c <= '9')
64 || ('A' <= c && c <= 'Z')
65 || ('a' <= c && c <= 'z')) {
66 stringBuilder.append(c);
67 } else {
68 words.add(stringBuilder.toString());
69 stringBuilder = new StringBuilder();
70 }
71 }
72
73 return words;
74 }
75 }