diff options
author | Artur Signell <artur.signell@itmill.com> | 2011-08-19 13:41:32 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2011-08-19 13:41:32 +0000 |
commit | 0e4687c8aaa0e63eafc41c5ee94524788b6dd303 (patch) | |
tree | e43b19835ecd12a43db009e7d3ce0fa4f36ce7a4 /tests | |
parent | de4063199b4835a3bf8425428a08d3ef6c0821af (diff) | |
download | vaadin-framework-0e4687c8aaa0e63eafc41c5ee94524788b6dd303.tar.gz vaadin-framework-0e4687c8aaa0e63eafc41c5ee94524788b6dd303.zip |
#7369 Test that ensures no Component contains a non-private final method
svn changeset:20526/svn branch:6.7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/vaadin/tests/server/component/FinalMethodTest.java | 68 |
1 files changed, 68 insertions, 0 deletions
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 index 0000000000..ad80007882 --- /dev/null +++ b/tests/src/com/vaadin/tests/server/component/FinalMethodTest.java @@ -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()); + } +} |