Hi Pavel,

here are some jtreg tests, which test the signatures of the changed API (raw & 
generic calls).

Note that, of course, the generic tests won't even compile before the generic 
JList patch is 
applied. So, if you care, you could: 
- remove the generic tests (should be simple)
- run the test with the unpatched version
- check them in
- upgrade the test along with the JList patch
- run them again
- check them both in

Please also  check the license header and the test annotations.

-Florian

Am Donnerstag, 3. September 2009 schrieb Florian Brunner:
> Hi Pavel,
>
> great news! :-)
>
> I will have a look at jtreg.
>
> -Florian
>
> Pavel Porvatov schrieb:
> > Hi Florian,
> >
> >> any news about my patch? What is the status? I understand that
> >> approving of the API is not a quick step, but then it's already 2-3
> >> months. And we need to do the same for all the other planed API-
> >> changes to "generify" Swing. It would be great if we could speed
> >> things up a bit again.
> >
> > The good news: the patch was approved on last Friday! So I can push
> > it. But many people asked about regression tests. Could you please
> > write such automatic tests for the fix. E.g.
> >
> > -----
> >         String[] strings = new String[] {"A string"};
> >
> >         new JList(strings);
> >
> >         Vector v1 = new Vector();
> >
> >         new JList(v1);
> >
> >         Vector<String> v2 = new Vector<String>();
> >
> >         new JList(v2);
> > -----
> > etc.
> >
> > Here you can find some info about test framework:
> > http://openjdk.java.net/jtreg/
> >
> > Thanks, Pavel.
> >
> >> What do you estimate, how much more time this step takes?
> >>
> >> Thanks.
> >> -Florian
> >>
> >> Am Mittwoch, 22. Juli 2009 schrieben Sie:
> >>> Hi Florian,
> >>>
> >>>> Hi Pavel,
> >>>>
> >>>> I hope you had nice holidays.
> >>>>
> >>>> Do you have any news about the patch?
> >>>
> >>> I'm awaiting approve of API changes. It's not a very quick step because
> >>> a lot of people should take a look at your changes and give approve for
> >>> it...
> >>>
> >>> Regards, Pavel
> >>>
> >>>> -Florian
> >>>>
> >>>> Am Freitag, 19. Juni 2009 schrieb Florian Brunner:
> >>>>> Hi Pavel,
> >>>>>
> >>>>> enjoy your holidays! My holidays start from 27th June till 8th
> >>>>> July, so
> >>>>> we can continue the work on generics afterwards again.
> >>>>>
> >>>>> -Florian
> >>>>>
> >>>>> Am Donnerstag, 11. Juni 2009 schrieb Pavel Porvatov:


diff -r 1729e34a0287 test/javax/swing/AbstractListModel/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/AbstractListModel/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+...@bug 6823603
+...@summary raw & generic AbstractListModel method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import javax.swing.AbstractListModel;
+import javax.swing.ListModel;
+
+public class bug6823603 {
+
+    /**
+     * @param <E> 
+     * @param args the command line arguments
+     */
+    public static <E> void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        @SuppressWarnings("serial")
+        ListModel rawTestModel = new AbstractListModel() {
+
+            public int getSize() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public Object getElementAt(int index) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        };
+    }
+
+    private static <E> void testGenericSignatures() {
+        @SuppressWarnings("serial")
+        ListModel<String> stringTestModel = new AbstractListModel<String>() {
+
+            public int getSize() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getElementAt(int index) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        };
+        
+        @SuppressWarnings("serial")
+        ListModel<E> genericTestModel = new AbstractListModel<E>() {
+
+            public int getSize() {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public E getElementAt(int index) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        };
+    }
+}
diff -r 1729e34a0287 test/javax/swing/DefaultListCellRenderer/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/DefaultListCellRenderer/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+...@test
+...@bug 6823603
+...@summary raw & generic DefaultListCellRenderer method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import java.awt.Component;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JList;
+
+public class bug6823603 {
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer();
+
+        String testEntry = "Test";
+        @SuppressWarnings("unchecked")
+        JList rawJList = new JList(new Object[]{testEntry});
+
+        Component listCellRendererComponent1 =
+                cellRenderer.getListCellRendererComponent(rawJList,
+                testEntry, 0, true, true);
+    }
+
+    private static void testGenericSignatures() {
+        DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer();
+
+        String testEntry = "Test";
+
+        JList<String> stringJList = new JList<String>(new String[]{testEntry});
+
+        Component listCellRendererComponent2 =
+                cellRenderer.getListCellRendererComponent(stringJList,
+                testEntry, 0, true, true);
+    }
+}
diff -r 1729e34a0287 test/javax/swing/DefaultListModel/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/DefaultListModel/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+...@test
+...@bug 6823603
+...@summary raw & generic DefaultListModel method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import java.util.Enumeration;
+import javax.swing.DefaultListModel;
+
+public class bug6823603 {
+
+    /**
+     * @param <E> 
+     * @param args the command line arguments
+     */
+    @SuppressWarnings("unchecked")
+    public static <E> void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        String testElement1 = "Test1";
+
+        DefaultListModel rawTestModel = new DefaultListModel();
+        rawTestModel.addElement(testElement1);
+        Object element1 = rawTestModel.getElementAt(0);
+        Enumeration<?> elements = rawTestModel.elements();
+        Object element2 = rawTestModel.elementAt(0);
+        Object firstElement = rawTestModel.firstElement();
+        Object lastElement = rawTestModel.lastElement();
+
+        String testElement2 = "Test2";
+        rawTestModel.setElementAt(testElement2, 0);
+        rawTestModel.insertElementAt(testElement1, 0);
+        Object element3 = rawTestModel.get(0);
+        Object element4 = rawTestModel.set(0, testElement2);
+        rawTestModel.add(0, testElement1);
+        Object removedElement = rawTestModel.remove(0);
+    }
+
+    private static void testGenericSignatures() {
+        String testElement1 = "Test1";
+
+        DefaultListModel<String> stringTestModel =
+                new DefaultListModel<String>();
+        stringTestModel.addElement(testElement1);
+        String element1 = stringTestModel.getElementAt(0);
+        Enumeration<String> elements = stringTestModel.elements();
+        String element2 = stringTestModel.elementAt(0);
+        String firstElement = stringTestModel.firstElement();
+        String lastElement = stringTestModel.lastElement();
+
+        String testElement2 = "Test2";
+        stringTestModel.setElementAt(testElement2, 0);
+        stringTestModel.insertElementAt(testElement1, 0);
+        String element3 = stringTestModel.get(0);
+        String element4 = stringTestModel.set(0, testElement2);
+        stringTestModel.add(0, testElement1);
+        String removedElement = stringTestModel.remove(0);
+    }
+}
diff -r 1729e34a0287 test/javax/swing/JList/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JList/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+...@test
+...@bug 6823603
+...@summary raw & generic JList method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListModel;
+import javax.swing.ListSelectionModel;
+
+public class bug6823603 {
+
+    /**
+     * @param <E> 
+     * @param args the command line arguments
+     */
+    @SuppressWarnings("unchecked")
+    public static <E> void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+
+        testGetSelectedValuesList(); // new method
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        String testElement1 = "Test1";
+
+        ListModel rawTestModel = new DefaultListModel();
+
+        JList rawTestList = new JList();
+        rawTestList = new JList(rawTestModel);
+        rawTestList = new JList(new Object[]{testElement1});
+        rawTestList = new JList(new Vector());
+        Object prototypeCellValue = rawTestList.getPrototypeCellValue();
+        rawTestList.setPrototypeCellValue(testElement1);
+        ListCellRenderer cellRenderer = rawTestList.getCellRenderer();
+        rawTestList.setCellRenderer(new DefaultListCellRenderer());
+        ListModel model = rawTestList.getModel();
+        rawTestList.setModel(rawTestModel);
+        rawTestList.setListData(new Object[]{testElement1});
+        rawTestList.setListData(new Vector());
+        
+        @SuppressWarnings("deprecation")
+        Object[] selectedValues = rawTestList.getSelectedValues();
+        Object selectedValue = rawTestList.getSelectedValue();
+    }
+
+    private static void testGenericSignatures() {
+        String testElement1 = "Test1";
+
+        ListModel<String> stringTestModel = new DefaultListModel<String>();
+
+        JList<String> stringTestList = new JList<String>();
+        stringTestList = new JList<String>(stringTestModel);
+        stringTestList = new JList<String>(new String[]{testElement1});
+        stringTestList = new JList<String>(new Vector<String>());
+        String prototypeCellValue = stringTestList.getPrototypeCellValue();
+        stringTestList.setPrototypeCellValue(testElement1);
+        ListCellRenderer<? super String> cellRenderer =
+                stringTestList.getCellRenderer();
+        stringTestList.setCellRenderer(new DefaultListCellRenderer());
+        ListModel<String> model = stringTestList.getModel();
+        stringTestList.setModel(stringTestModel);
+        stringTestList.setListData(new String[]{testElement1});
+        stringTestList.setListData(new Vector<String>());
+
+        @SuppressWarnings("deprecation")
+        Object[] selectedValues = stringTestList.getSelectedValues();
+        String selectedValue = stringTestList.getSelectedValue();
+    }
+
+    private static void testGetSelectedValuesList() {
+        Vector<Integer> data = new Vector<Integer>();
+        for (int i = 0; i < 10; i++) {
+            data.add(i);
+        }
+        JList<Integer> list = new JList<Integer>(data);
+        list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+        list.setSelectedIndices(new int[]{1, 2, 3, 5, 6, 8});
+
+        @SuppressWarnings("deprecation")
+        Object[] expectedSelectedValues = list.getSelectedValues();
+        List<Integer> selectedValuesList = list.getSelectedValuesList();
+        assertEquals(expectedSelectedValues, selectedValuesList.toArray());
+    }
+
+    private static void assertEquals(Object[] expectedArray,
+            Object[] actualArray) {
+        if (!Arrays.equals(expectedArray, actualArray)) {
+            throw new RuntimeException("Expected: " + Arrays.toString(
+                    expectedArray) + " but was: " + Arrays.toString(actualArray));
+        }
+    }
+}
diff -r 1729e34a0287 test/javax/swing/ListCellRenderer/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/ListCellRenderer/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+...@test
+...@bug 6823603
+...@summary raw & generic ListCellRenderer method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import java.awt.Component;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+public class bug6823603 {
+
+    /**
+     * @param <E> 
+     * @param args the command line arguments
+     */
+    @SuppressWarnings("unchecked")
+    public static <E> void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        ListCellRenderer rawTestCellRenderer = new DefaultListCellRenderer();
+        String testEntry = "Test";
+        @SuppressWarnings("unchecked")
+        JList rawJList = new JList(new Object[]{testEntry});
+
+        Component listCellRendererComponent1 =
+                rawTestCellRenderer.getListCellRendererComponent(rawJList,
+                testEntry, 0, true, true);
+    }
+
+    private static void testGenericSignatures() {
+        ListCellRenderer<Object> stringTestCellRenderer =
+                new DefaultListCellRenderer();
+        String testEntry = "Test";
+        JList<String> stringJList = new JList<String>(new String[]{testEntry});
+
+        Component listCellRendererComponent2 =
+                stringTestCellRenderer.getListCellRendererComponent(stringJList,
+                testEntry, 0, true, true);
+    }
+}
diff -r 1729e34a0287 test/javax/swing/ListModel/6823603/bug6823603.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/ListModel/6823603/bug6823603.java	Sat Sep 12 20:55:00 2009 +0200
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+...@test
+...@bug 6823603
+...@summary raw & generic ListModel method/ constructor signature test
+...@author Florian Brunner
+...@run main bug6823603
+ */
+import javax.swing.DefaultListModel;
+import javax.swing.ListModel;
+
+public class bug6823603 {
+
+    /**
+     * @param <E> 
+     * @param args the command line arguments
+     */
+    @SuppressWarnings("unchecked")
+    public static <E> void main(String[] args) {
+        testRawSignatures();
+        testGenericSignatures();
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void testRawSignatures() {
+        String testElement1 = "Test1";
+        DefaultListModel testModel = new DefaultListModel();
+        testModel.addElement(testElement1);
+        ListModel rawTestModel = testModel;
+        Object element1 = rawTestModel.getElementAt(0);
+    }
+
+    private static void testGenericSignatures() {
+        String testElement1 = "Test1";
+        DefaultListModel<String> testModel = new DefaultListModel<String>();
+        testModel.addElement(testElement1);
+        ListModel<String> stringTestModel = testModel;
+        String element1 = stringTestModel.getElementAt(0);
+    }
+}

Reply via email to