View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, Steve Meyfroidt 4 * All rights reserved. 5 * Email: smeyfroi@users.sourceforge.net 6 * 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * Neither the name "Scope" nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * 36 * 37 * $Id: TestSListCellRenderer.java,v 1.5 2002/08/05 13:19:26 ludovicc Exp $ 38 */ 39 40 41 package test.view.swing; 42 43 44 import java.awt.Component; 45 import javax.swing.ImageIcon; 46 import javax.swing.JList; 47 import junit.framework.TestCase; 48 import org.apache.commons.logging.LogFactory;import org.apache.commons.logging.Log; 49 import org.scopemvc.core.Selector; 50 import org.scopemvc.view.swing.SListCellRenderer; 51 52 53 /*** 54 * <P> 55 * </P> 56 * 57 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>;Steve Meyfroidt</A> 58 * @version $Revision: 1.5 $ $Date: 2002/08/05 13:19:26 $ 59 */ 60 public final class TestSListCellRenderer extends TestCase { 61 62 63 private static final Log LOG = LogFactory.getLog(TestSListCellRenderer.class); 64 65 66 private SListCellRenderer renderer; 67 private JList list; 68 private SwingDummyModel model; 69 70 71 public TestSListCellRenderer(String inName) { 72 super(inName); 73 } 74 75 76 protected void setUp() throws Exception { 77 78 renderer = new SListCellRenderer(); 79 80 list = new JList(); 81 list.setCellRenderer(renderer); 82 83 model = new SwingDummyModel(); 84 } 85 86 87 protected void tearDown() { 88 } 89 90 91 public void testRendererDefault1() throws Exception { 92 Component c = renderer.getListCellRendererComponent(list, "test", 0, false, false); 93 assertEquals("test", renderer.getText()); 94 assertNull(renderer.getIcon()); 95 } 96 97 98 public void testRendererDefault2() throws Exception { 99 ImageIcon icon = new ImageIcon(); 100 Component c = renderer.getListCellRendererComponent(list, icon, 0, false, false); 101 assertEquals("", renderer.getText()); 102 assertSame(icon, renderer.getIcon()); 103 } 104 105 106 public void testRendererText() throws Exception { 107 renderer.setTextSelector(Selector.fromString("stringProperty")); 108 Component c = renderer.getListCellRendererComponent(list, model, 0, false, false); 109 assertEquals(model.getStringProperty(), renderer.getText()); 110 assertNull(renderer.getIcon()); 111 } 112 113 114 public void testRendererIcon() throws Exception { 115 renderer.setIconSelector(Selector.fromString("iconProperty")); 116 Component c = renderer.getListCellRendererComponent(list, model, 0, false, false); 117 assertSame(model.getIconProperty(), renderer.getIcon()); 118 assertEquals("", renderer.getText()); 119 } 120 121 122 public void testRendererTextIcon() throws Exception { 123 renderer.setIconSelector(Selector.fromString("iconProperty")); 124 renderer.setTextSelector(Selector.fromString("stringProperty")); 125 Component c = renderer.getListCellRendererComponent(list, model, 0, false, false); 126 assertEquals(model.getStringProperty(), renderer.getText()); 127 assertSame(model.getIconProperty(), renderer.getIcon()); 128 } 129 130 131 public void testConvenience() throws Exception { 132 renderer.setIconSelectorString("iconProperty"); 133 renderer.setTextSelectorString("stringProperty"); 134 Component c = renderer.getListCellRendererComponent(list, model, 0, false, false); 135 assertEquals(model.getStringProperty(), renderer.getText()); 136 assertSame(model.getIconProperty(), renderer.getIcon()); 137 } 138 }

This page was automatically generated by Maven