]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7369 Test that ensures no Component contains a non-private final method
authorArtur Signell <artur.signell@itmill.com>
Fri, 19 Aug 2011 13:41:32 +0000 (13:41 +0000)
committerArtur Signell <artur.signell@itmill.com>
Fri, 19 Aug 2011 13:41:32 +0000 (13:41 +0000)
svn changeset:20526/svn branch:6.7

tests/src/com/vaadin/tests/server/component/FinalMethodTest.java [new file with mode: 0644]

diff --git a/tests/src/com/vaadin/tests/server/component/FinalMethodTest.java b/tests/src/com/vaadin/tests/server/component/FinalMethodTest.java
new file mode 100644 (file)
index 0000000..ad80007
--- /dev/null
@@ -0,0 +1,68 @@
+package com.vaadin.tests.server.component;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import com.vaadin.tests.VaadinClasses;
+import com.vaadin.ui.Component;
+
+public class FinalMethodTest extends TestCase {
+
+    // public void testThatContainersHaveNoFinalMethods() {
+    // HashSet<Class<?>> tested = new HashSet<Class<?>>();
+    // for (Class<?> c : VaadinClasses.getAllServerSideClasses()) {
+    // if (Container.class.isAssignableFrom(c)) {
+    // ensureNoFinalMethods(c, tested);
+    // }
+    // }
+    // }
+
+    public void testThatComponentsHaveNoFinalMethods() {
+        HashSet<Class<?>> tested = new HashSet<Class<?>>();
+        for (Class<? extends Component> c : VaadinClasses.getComponents()) {
+            ensureNoFinalMethods(c, tested);
+        }
+    }
+
+    private void ensureNoFinalMethods(Class<?> c, HashSet<Class<?>> tested) {
+        if (tested.contains(c)) {
+            return;
+        }
+
+        tested.add(c);
+
+        if (c == Object.class) {
+            return;
+        }
+        System.out.println("Checking " + c.getName());
+        for (Method m : c.getDeclaredMethods()) {
+            if (isPrivate(m)) {
+                continue;
+            }
+            if (isFinal(m)) {
+                String error = "Class " + c.getName() + " contains a "
+                        + (isPublic(m) ? "public" : "non-public")
+                        + " final method: " + m.getName();
+                // System.err.println(error);
+                throw new RuntimeException(error);
+            }
+        }
+        ensureNoFinalMethods(c.getSuperclass(), tested);
+
+    }
+
+    private boolean isFinal(Method m) {
+        return Modifier.isFinal(m.getModifiers());
+    }
+
+    private boolean isPrivate(Method m) {
+        return Modifier.isPrivate(m.getModifiers());
+    }
+
+    private boolean isPublic(Method m) {
+        return Modifier.isPublic(m.getModifiers());
+    }
+}