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.component;
21
22 import org.junit.jupiter.api.Assertions;
23 import org.junit.jupiter.api.Test;
24
25 import javax.faces.component.UIComponent;
26 import java.lang.reflect.Method;
27 import java.lang.reflect.Modifier;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
31
32 public class MethodOverwritingOfGeneratedUIComponentsUnitTest extends AbstractGeneratedUIComponentsUnitTest {
33
34 private static final List<String> IGNORED_METHODS
35 = Arrays.asList("getFamily", "saveState", "restoreState", "getEventNames", "getDefaultEventName");
36 private static final MethodOfComponentList IGNORED_METHODS_PER_COMPONENT = new MethodOfComponentList();
37
38 static {
39 IGNORED_METHODS_PER_COMPONENT.add("isResizable", UIColumn.class);
40 IGNORED_METHODS_PER_COMPONENT.add("isResizable", UIColumnNode.class);
41 IGNORED_METHODS_PER_COMPONENT.add("isShowRootJunction", UISheet.class);
42 IGNORED_METHODS_PER_COMPONENT.add("isShowRootJunction", UITree.class);
43 IGNORED_METHODS_PER_COMPONENT.add("isPlain", UIOut.class);
44 IGNORED_METHODS_PER_COMPONENT.add("isPlain", UIForm.class);
45 }
46
47 @Test
48 public void test() {
49
50 for (final Class<? extends UIComponent> uiComponent : getUiComponents()) {
51 final Method[] methods = uiComponent.getMethods();
52 for (final Method method : methods) {
53
54 if (!method.getDeclaringClass().equals(uiComponent)) {
55
56 continue;
57 }
58
59 if (IGNORED_METHODS.contains(method.getName())) {
60 continue;
61 }
62
63 if (IGNORED_METHODS_PER_COMPONENT.contains(method.getName(), uiComponent)) {
64 continue;
65 }
66
67 for (Class<?> superClass = uiComponent.getSuperclass();
68 superClass != null;
69 superClass = superClass.getSuperclass()) {
70 final Method superMethod;
71 try {
72 superMethod = superClass.getMethod(method.getName(), method.getParameterTypes());
73 } catch (final NoSuchMethodException e) {
74
75 continue;
76 }
77
78 if (!Modifier.isAbstract(superMethod.getModifiers())) {
79 Assertions.fail(method.getName() + " of " + uiComponent.getName()
80 + " hides a concrete super method (but is not in the ignore list).");
81 break;
82 }
83 }
84 }
85 }
86 }
87
88 private static class MethodOfComponentList {
89
90 private List<String> list = new ArrayList<>();
91
92 public void add(final String method, final Class<? extends UIComponent> component) {
93 list.add(concatenate(method, component));
94 }
95
96 public boolean contains(final String method, final Class<? extends UIComponent> component) {
97 return list.contains(concatenate(method, component));
98 }
99
100 private String concatenate(final String method, final Class<? extends UIComponent> component) {
101 return method + '@' + component.getName();
102 }
103
104 }
105 }