1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.configuration;
16
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.List;
21
22 import org.htmlunit.javascript.HtmlUnitScriptable;
23 import org.junit.jupiter.api.Assertions;
24 import org.junit.jupiter.api.Test;
25
26 /**
27 * Tests for {@link WorkerJavaScriptConfiguration}.
28 *
29 * @author Ronald Brill
30 */
31 public class WorkerJavaScriptConfigurationTest {
32
33 /**
34 * Test of order.
35 */
36 @Test
37 public void treeOrder() {
38 final List<String> defined = new ArrayList<>(WorkerJavaScriptConfiguration.CLASSES_.length);
39
40 final HashMap<Integer, List<String>> levels = new HashMap<>();
41 for (final Class<?> c : WorkerJavaScriptConfiguration.CLASSES_) {
42 defined.add(c.getSimpleName());
43
44 int level = 1;
45 Class<?> parent = c.getSuperclass();
46 while (parent != HtmlUnitScriptable.class) {
47 level++;
48 parent = parent.getSuperclass();
49 }
50
51 List<String> clsAtLevel = levels.get(level);
52 if (clsAtLevel == null) {
53 clsAtLevel = new ArrayList<>();
54 levels.put(level, clsAtLevel);
55 }
56 clsAtLevel.add(c.getSimpleName());
57 }
58
59 final List<String> all = new ArrayList<>(WorkerJavaScriptConfiguration.CLASSES_.length);
60 for (int level = 1; level <= levels.size(); level++) {
61 final List<String> clsAtLevel = levels.get(level);
62 Collections.sort(clsAtLevel);
63 all.addAll(clsAtLevel);
64
65 // dump
66 /*
67 final String indent = " ";
68 System.out.println(indent + " // level " + level);
69
70 System.out.print(indent);
71 int chars = indent.length();
72 for (final String cls : clsAtLevel) {
73 final String toPrint = " " + cls + ".class,";
74 chars += toPrint.length();
75 if (chars > 120) {
76 System.out.println();
77 System.out.print(indent);
78 chars = indent.length() + toPrint.length();
79 }
80 System.out.print(toPrint);
81 }
82 System.out.println();
83 */
84 }
85 Assertions.assertEquals(all, defined);
86 }
87 }