From: Artur Signell Date: Fri, 19 Aug 2011 13:41:32 +0000 (+0000) Subject: #7369 Test that ensures no Component contains a non-private final method X-Git-Tag: 6.7.0.beta1~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0e4687c8aaa0e63eafc41c5ee94524788b6dd303;p=vaadin-framework.git #7369 Test that ensures no Component contains a non-private final method svn changeset:20526/svn branch:6.7 --- 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> tested = new HashSet>(); + // for (Class c : VaadinClasses.getAllServerSideClasses()) { + // if (Container.class.isAssignableFrom(c)) { + // ensureNoFinalMethods(c, tested); + // } + // } + // } + + public void testThatComponentsHaveNoFinalMethods() { + HashSet> tested = new HashSet>(); + for (Class c : VaadinClasses.getComponents()) { + ensureNoFinalMethods(c, tested); + } + } + + private void ensureNoFinalMethods(Class c, HashSet> 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()); + } +}