View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }