]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5692 Generics and warnings cleanup: more test classes with slight modifications
authorHenri Sara <henri.sara@itmill.com>
Tue, 5 Oct 2010 06:21:13 +0000 (06:21 +0000)
committerHenri Sara <henri.sara@itmill.com>
Tue, 5 Oct 2010 06:21:13 +0000 (06:21 +0000)
svn changeset:15387/svn branch:6.5

tests/src/com/vaadin/tests/ListenerOrder.java
tests/src/com/vaadin/tests/OrderedLayoutSwapComponents.java
tests/src/com/vaadin/tests/Parameters.java
tests/src/com/vaadin/tests/TestBench.java
tests/src/com/vaadin/tests/util/RandomComponents.java
tests/src/com/vaadin/tests/util/TestClickListener.java

index 3b7329c3844d84a0c5fd842485b342dbe61bd92e..c1d6245222827818c50e64b676964fd93bfa1fb5 100644 (file)
@@ -24,7 +24,7 @@ public class ListenerOrder extends com.vaadin.Application implements
 
     Select s1;
 
-    HashMap buttonListeners = new HashMap();
+    HashMap<String, Integer> buttonListeners = new HashMap<String, Integer>();
 
     @Override
     public void init() {
@@ -88,7 +88,7 @@ public class ListenerOrder extends com.vaadin.Application implements
         s1.addListener((ValueChangeListener) this);
 
         Item i = s1.getItem("second");
-        for (Iterator it = i.getItemPropertyIds().iterator(); it.hasNext();) {
+        for (Iterator<?> it = i.getItemPropertyIds().iterator(); it.hasNext();) {
             Object o = it.next();
             System.out.println("[" + o + "]");
         }
@@ -119,7 +119,7 @@ public class ListenerOrder extends com.vaadin.Application implements
         public MyClickListener(String name) {
             Integer count = null;
             try {
-                count = (Integer) buttonListeners.get(name);
+                count = buttonListeners.get(name);
                 count = new Integer(count.intValue() + 1);
                 buttonListeners.put(name, count);
             } catch (Exception e) {
index 1c21cb25bd767b8a8216118c79a4d67466622c6a..dab5eec54308236dd771274944d7a60d7060ad59 100644 (file)
@@ -23,7 +23,7 @@ public class OrderedLayoutSwapComponents extends CustomComponent {
 
     private final OrderedLayout main;
 
-    ArrayList order = new ArrayList();
+    ArrayList<MyComponent> order = new ArrayList<MyComponent>();
 
     public OrderedLayoutSwapComponents() {
 
@@ -61,7 +61,7 @@ public class OrderedLayoutSwapComponents extends CustomComponent {
             up.addListener(new Button.ClickListener() {
                 public void buttonClick(ClickEvent event) {
                     int newIndex = order.indexOf(MyComponent.this) - 1;
-                    MyComponent old = (MyComponent) order.get(newIndex);
+                    MyComponent old = order.get(newIndex);
                     main.replaceComponent(old, MyComponent.this);
                     order.remove(MyComponent.this);
                     order.add(newIndex, MyComponent.this);
@@ -78,7 +78,7 @@ public class OrderedLayoutSwapComponents extends CustomComponent {
             down.addListener(new Button.ClickListener() {
                 public void buttonClick(ClickEvent event) {
                     int newIndex = order.indexOf(MyComponent.this) + 1;
-                    MyComponent old = (MyComponent) order.get(newIndex);
+                    MyComponent old = order.get(newIndex);
                     main.replaceComponent(old, MyComponent.this);
                     order.remove(MyComponent.this);
                     order.add(newIndex, MyComponent.this);
index bb026a8955952850a9e27167db491ebf2579b36f..a8957c0f6af2040286c31d6616f16d98b0439898 100644 (file)
@@ -108,11 +108,12 @@ public class Parameters extends com.vaadin.Application implements URIHandler,
      * Handles GET parameters, in this demo GET parameteres are used to
      * communicate with EmbeddedToolkit.jsp
      */
-    public void handleParameters(Map parameters) {
+    public void handleParameters(Map<String, String[]> parameters) {
         params.removeAllItems();
-        for (final Iterator i = parameters.keySet().iterator(); i.hasNext();) {
-            final String name = (String) i.next();
-            final String[] values = (String[]) parameters.get(name);
+        for (final Iterator<String> i = parameters.keySet().iterator(); i
+                .hasNext();) {
+            final String name = i.next();
+            final String[] values = parameters.get(name);
             String v = "";
             for (int j = 0; j < values.length; j++) {
                 if (v.length() > 0) {
index a670d40708dc2c0d9069d814c726877ced73b80d..985c06e7746644771d2a72b8647871aa4c5dd7b1 100644 (file)
@@ -58,7 +58,8 @@ public class TestBench extends com.vaadin.Application implements
 
     Panel bodyLayout = new Panel();
 
-    HashMap itemCaptions = new HashMap();
+    // TODO this could probably be a simple Set
+    HashMap<Class<?>, String> itemCaptions = new HashMap<Class<?>, String>();
 
     @Override
     public void init() {
@@ -67,10 +68,10 @@ public class TestBench extends com.vaadin.Application implements
         for (int p = 0; p < testablePackages.length; p++) {
             testables.addItem(testablePackages[p]);
             try {
-                final List testableClasses = getTestableClassesForPackage(testablePackages[p]);
-                for (final Iterator it = testableClasses.iterator(); it
+                final List<Class<?>> testableClasses = getTestableClassesForPackage(testablePackages[p]);
+                for (final Iterator<Class<?>> it = testableClasses.iterator(); it
                         .hasNext();) {
-                    final Class t = (Class) it.next();
+                    final Class<?> t = it.next();
                     // ignore TestBench itself
                     if (t.equals(TestBench.class)) {
                         continue;
@@ -100,15 +101,16 @@ public class TestBench extends com.vaadin.Application implements
 
         menu = new Tree("Testables", testables);
 
-        for (final Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) {
-            final Class testable = (Class) i.next();
+        for (final Iterator<Class<?>> i = itemCaptions.keySet().iterator(); i
+                .hasNext();) {
+            final Class<?> testable = i.next();
             // simplify captions
             final String name = testable.getName().substring(
                     testable.getName().lastIndexOf('.') + 1);
             menu.setItemCaption(testable, name);
         }
         // expand all root items
-        for (final Iterator i = menu.rootItemIds().iterator(); i.hasNext();) {
+        for (final Iterator<?> i = menu.rootItemIds().iterator(); i.hasNext();) {
             menu.expandItemsRecursively(i.next());
         }
 
@@ -128,11 +130,11 @@ public class TestBench extends com.vaadin.Application implements
                     // try to find a proper test class
 
                     // exact match
-                    Iterator iterator = menu.getItemIds().iterator();
+                    Iterator<?> iterator = menu.getItemIds().iterator();
                     while (iterator.hasNext()) {
                         Object next = iterator.next();
                         if (next instanceof Class) {
-                            Class c = (Class) next;
+                            Class<?> c = (Class<?>) next;
                             String string = c.getName();
                             if (string.equals(fragment)) {
                                 menu.setValue(c);
@@ -147,7 +149,7 @@ public class TestBench extends com.vaadin.Application implements
                     while (iterator.hasNext()) {
                         Object next = iterator.next();
                         if (next instanceof Class) {
-                            Class c = (Class) next;
+                            Class<?> c = (Class<?>) next;
                             String string = c.getSimpleName();
                             if (string.equals(fragment)) {
                                 menu.setValue(c);
@@ -161,7 +163,7 @@ public class TestBench extends com.vaadin.Application implements
                     while (iterator.hasNext()) {
                         Object next = iterator.next();
                         if (next instanceof Class) {
-                            Class c = (Class) next;
+                            Class<?> c = (Class<?>) next;
                             String string = c.getSimpleName();
                             if (string.startsWith("Ticket" + fragment)) {
                                 menu.setValue(c);
@@ -176,7 +178,7 @@ public class TestBench extends com.vaadin.Application implements
                     while (iterator.hasNext()) {
                         Object next = iterator.next();
                         if (next instanceof Class) {
-                            Class c = (Class) next;
+                            Class<?> c = (Class<?>) next;
                             String string = c.getSimpleName();
                             if (string.toLowerCase().contains(
                                     fragment.toLowerCase())) {
@@ -210,7 +212,7 @@ public class TestBench extends com.vaadin.Application implements
         setMainWindow(mainWindow);
     }
 
-    private Component createTestable(Class c) {
+    private Component createTestable(Class<?> c) {
         try {
             final Application app = (Application) c.newInstance();
             app.init();
@@ -245,7 +247,7 @@ public class TestBench extends com.vaadin.Application implements
 
         final Object o = menu.getValue();
         if (o != null && o instanceof Class) {
-            final Class c = (Class) o;
+            final Class<?> c = (Class<?>) o;
             final String title = c.getName();
             bodyLayout.setCaption(title);
             bodyLayout.addComponent(createTestable(c));
@@ -262,9 +264,9 @@ public class TestBench extends com.vaadin.Application implements
      * @return
      * @throws ClassNotFoundException
      */
-    public static List getTestableClassesForPackage(String packageName)
+    public static List<Class<?>> getTestableClassesForPackage(String packageName)
             throws Exception {
-        final ArrayList directories = new ArrayList();
+        final ArrayList<File> directories = new ArrayList<File>();
         try {
             final ClassLoader cld = Thread.currentThread()
                     .getContextClassLoader();
@@ -273,9 +275,9 @@ public class TestBench extends com.vaadin.Application implements
             }
             final String path = packageName.replace('.', '/');
             // Ask for all resources for the path
-            final Enumeration resources = cld.getResources(path);
+            final Enumeration<URL> resources = cld.getResources(path);
             while (resources.hasMoreElements()) {
-                final URL url = (URL) resources.nextElement();
+                final URL url = resources.nextElement();
                 directories.add(new File(url.getFile()));
             }
         } catch (final Exception x) {
@@ -283,10 +285,10 @@ public class TestBench extends com.vaadin.Application implements
                     + " does not appear to be a valid package.");
         }
 
-        final ArrayList classes = new ArrayList();
+        final ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
         // For every directory identified capture all the .class files
-        for (final Iterator it = directories.iterator(); it.hasNext();) {
-            final File directory = (File) it.next();
+        for (final Iterator<File> it = directories.iterator(); it.hasNext();) {
+            final File directory = it.next();
             if (directory.exists()) {
                 // Get the list of the files contained in the package
                 final String[] files = directory.list();
@@ -296,7 +298,7 @@ public class TestBench extends com.vaadin.Application implements
                         // removes the .class extension
                         final String p = packageName + '.'
                                 + files[j].substring(0, files[j].length() - 6);
-                        final Class c = Class.forName(p);
+                        final Class<?> c = Class.forName(p);
                         if (c.getSuperclass() != null) {
                             if ((c.getSuperclass()
                                     .equals(com.vaadin.Application.class))) {
index f857563cdd3d3dc1acc148459c3ae793022f541c..f9b1eba7ecf2fd2800483a65ea83e212540e6f01 100644 (file)
@@ -102,17 +102,16 @@ public class RandomComponents {
             ts.setCaption("TabSheet_" + caption);
             // randomly select one of the tabs
             final int selectedTab = seededRandom.nextInt(3);
-            final ArrayList tabs = new ArrayList();
+            final ArrayList<ComponentContainer> tabs = new ArrayList<ComponentContainer>();
             for (int i = 0; i < 3; i++) {
                 String tabCaption = "tab" + i;
                 if (selectedTab == i) {
                     tabCaption = "tabX";
                 }
                 tabs.add(new OrderedLayout());
-                ts.addTab((ComponentContainer) tabs.get(tabs.size() - 1),
-                        tabCaption, null);
+                ts.addTab(tabs.get(tabs.size() - 1), tabCaption, null);
             }
-            ts.setSelectedTab((ComponentContainer) tabs.get(selectedTab));
+            ts.setSelectedTab(tabs.get(selectedTab));
             result = ts;
             break;
         }
index 730452ac72eb66a8e99c64f5a3591c6ef445983f..95b9cf2d40f20c9c5880cc852d3ce5bf406096eb 100644 (file)
@@ -7,7 +7,7 @@ import com.vaadin.ui.Button.ClickEvent;
 
 public class TestClickListener implements Button.ClickListener {
 
-    private static final HashMap buttonListeners = new HashMap();
+    private static final HashMap<String, Integer> buttonListeners = new HashMap<String, Integer>();
 
     String name = "";
     int count = 0;
@@ -15,7 +15,7 @@ public class TestClickListener implements Button.ClickListener {
     public TestClickListener(String name) {
         Integer count = null;
         try {
-            count = (Integer) buttonListeners.get(name);
+            count = buttonListeners.get(name);
             count = new Integer(count.intValue() + 1);
             buttonListeners.put(name, count);
         } catch (Exception e) {