⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexedpropertytestcase.java

📁 这是一个有关common beanutils 的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Id: IndexedPropertyTestCase.java 546480 2007-06-12 13:35:32Z niallp $
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 

package org.apache.commons.beanutils;

import java.util.List;
import java.util.ArrayList;
import java.beans.IndexedPropertyDescriptor;
import java.beans.PropertyDescriptor;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;




/**
 * <p>Test Case for the Indexed Properties.</p>
 *
 * @author Niall Pemberton
 * @version $Revision: 546480 $ $Date: 2007-06-12 14:35:32 +0100 (Tue, 12 Jun 2007) $
 */

public class IndexedPropertyTestCase extends TestCase {

    private static final Log log = LogFactory.getLog(IndexedPropertyTestCase.class);

    // ---------------------------------------------------- Instance Variables

    /**
     * The test bean for each test.
     */
    private IndexedTestBean bean = null;
    private BeanUtilsBean beanUtilsBean; 
    private PropertyUtilsBean propertyUtilsBean;
    private String[] testArray;
    private String[] newArray;
    private List testList;
    private List newList;
    private ArrayList arrayList;

    // ---------------------------------------------------------- Constructors

    /**
     * Construct a new instance of this test case.
     *
     * @param name Name of the test case
     */
    public IndexedPropertyTestCase(String name) {
        super(name);
    }


    // -------------------------------------------------- Overall Test Methods


    /**
     * Set up instance variables required by this test case.
     */
    public void setUp() {

        // BeanUtils
        beanUtilsBean = new BeanUtilsBean();
        propertyUtilsBean = beanUtilsBean.getPropertyUtils();

        // initialize Arrays and Lists
        testArray= new String[] {"array-0", "array-1", "array-2"};
        newArray = new String[]  {"newArray-0", "newArray-1", "newArray-2"};

        testList = new ArrayList();
        testList.add("list-0");
        testList.add("list-1");
        testList.add("list-2");

        newList = new ArrayList();
        newList.add("newList-0");
        newList.add("newList-1");
        newList.add("newList-2");

        arrayList = new ArrayList();
        arrayList.add("arrayList-0");
        arrayList.add("arrayList-1");
        arrayList.add("arrayList-2");

        // initialize Test Bean  properties
        bean = new IndexedTestBean();
        bean.setStringArray(testArray);
        bean.setStringList(testList);
        bean.setArrayList(arrayList);
    }


    /**
     * Return the tests included in this test suite.
     */
    public static Test suite() {
        return (new TestSuite(IndexedPropertyTestCase.class));
    }

    /**
     * Tear down instance variables required by this test case.
     */
    public void tearDown() {
        bean = null;
    }


    // ------------------------------------------------ Individual Test Methods

    /**
     * Test IndexedPropertyDescriptor for an Array
     */
    public void testArrayIndexedPropertyDescriptor() {

        try {
            PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Descriptor", descriptor);
            assertEquals("Not IndexedPropertyDescriptor", 
                         IndexedPropertyDescriptor.class,
                         descriptor.getClass());
            assertEquals("PropertDescriptor Type invalid", 
                         testArray.getClass(),
                         descriptor.getPropertyType());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test IndexedPropertyDescriptor for a List
     */
    public void testListIndexedPropertyDescriptor() {

        try {
            PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
            assertNotNull("No List Descriptor", descriptor);
            assertEquals("Not IndexedPropertyDescriptor", 
                         IndexedPropertyDescriptor.class,
                         descriptor.getClass());
            assertEquals("PropertDescriptor Type invalid", 
                         List.class,
                         descriptor.getPropertyType());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test IndexedPropertyDescriptor for an ArrayList
     */
    public void testArrayListIndexedPropertyDescriptor() {

        try {
            PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
            assertNotNull("No ArrayList Descriptor", descriptor);
            assertEquals("Not IndexedPropertyDescriptor", 
                         IndexedPropertyDescriptor.class,
                         descriptor.getClass());
            assertEquals("PropertDescriptor Type invalid", 
                         ArrayList.class,
                         descriptor.getPropertyType());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Read Method for an Array
     */
    public void testArrayReadMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Read Method", descriptor.getReadMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Write Method for an Array
     */
    public void testArrayWriteMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Write Method", descriptor.getWriteMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Indexed Read Method for an Array
     */
    public void testArrayIndexedReadMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Indexed Read Method", descriptor.getIndexedReadMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Indexed Write Method for an Array
     */
    public void testArrayIndexedWriteMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
            assertNotNull("No Array Indexed Write Method", descriptor.getIndexedWriteMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Read Method for a List
     *
     * JDK 1.3.1_04: Test Passes
     * JDK 1.4.2_05: Test Fails - getter which returns java.util.List not returned
     *                            by IndexedPropertyDescriptor.getReadMethod();
     */
    public void testListReadMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
            assertNotNull("No List Read Method", descriptor.getReadMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Write Method for a List
     *
     * JDK 1.3.1_04: Test Passes
     * JDK 1.4.2_05: Test Fails - setter whith java.util.List argument not returned
     *                            by IndexedPropertyDescriptor.getWriteMethod();
     */
    public void testListWriteMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
            assertNotNull("No List Write Method", descriptor.getWriteMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Indexed Read Method for a List
     */
    public void testListIndexedReadMethod() {

        try {
            IndexedPropertyDescriptor descriptor = 
                 (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
            assertNotNull("No List Indexed Read Method", descriptor.getIndexedReadMethod());
        } catch(Exception e) {
            fail("Threw exception " + e);
        }
    }

    /**
     * Test Indexed Write Method for a List

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -