home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons Attributes example source code file (AttributeIndexTestCase.java)

This example Commons Attributes source code file (AttributeIndexTestCase.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons Attributes tags/keywords

attributeindex, class, collection, collection, exception, exception, file, inner, io, net, network, reflection, testattribute, testattribute, testclass, testclass, testclass_inner, urlclassloader, util

The Commons Attributes AttributeIndexTestCase.java source code

 * Copyright 2003-2004 The Apache Software Foundation
 * Licensed 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,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.apache.commons.attributes.test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.AttributeIndex;
import junit.framework.TestCase;

public class AttributeIndexTestCase extends TestCase {
    private URLClassLoader cl = null;
    private AttributeIndex index = null;
    private Class TESTCLASS = null;
    private Class TESTCLASS_INNER = null;
    private Class TESTATTRIBUTE = null;
    public void setUp () throws Exception {
        cl = new URLClassLoader (new URL[]{new File ("target/cl2/cl2.jar").toURL ()}, getClass().getClassLoader ());
        index = new AttributeIndex (cl);
        TESTCLASS = cl.loadClass ("TestClass");
        TESTCLASS_INNER = cl.loadClass ("TestClass$Inner");
        TESTATTRIBUTE = cl.loadClass ("TestAttribute");
    public void testAttributeIndexCompatible () throws Exception {
        Collection classes = index.getClassesWithAttribute ("TestAttribute");
        System.out.println (classes);
        assertEquals (2, classes.size ());
        assertTrue (classes.contains ("TestClass"));
        assertTrue (classes.contains ("TestClass.Inner"));        
    public void testClasses () throws Exception {
        Collection classes = index.getClasses (TESTATTRIBUTE);
        System.out.println (classes);
        assertEquals (2, classes.size ());
        assertTrue (classes.contains (TESTCLASS));
        assertTrue (classes.contains (TESTCLASS_INNER));
    public void testMethods () throws Exception {
        Collection methods = index.getMethods (TESTATTRIBUTE);
        System.out.println (methods);
        assertEquals (1, methods.size ());
        assertTrue (methods.contains (TESTCLASS.getDeclaredMethods()[0]));
    public void testConstructors () throws Exception {
        Collection ctors = index.getConstructors (TESTATTRIBUTE);
        System.out.println (ctors);
        assertEquals (1, ctors.size ());
        assertTrue (ctors.contains (TESTCLASS.getDeclaredConstructors()[0]));
    public void testConstructorParameters () throws Exception {
        Collection ctors = index.getConstructorParameters (TESTATTRIBUTE);
        System.out.println (ctors);
        assertEquals (1, ctors.size ());
        assertTrue (ctors.contains (new AttributeIndex.ConstructorParameter (TESTCLASS.getDeclaredConstructors()[0], 0)));
    public void testMethodParameters () throws Exception {
        Collection methods = index.getMethodParameters (TESTATTRIBUTE);
        System.out.println (methods);
        assertEquals (1, methods.size ());
        assertTrue (methods.contains (new AttributeIndex.MethodParameter (TESTCLASS.getDeclaredMethods()[0], 0)));
    public void testMethodsReturning () throws Exception {
        Collection methods = index.getMethodsReturning (TESTATTRIBUTE);
        System.out.println (methods);
        assertEquals (1, methods.size ());
        assertTrue (methods.contains (TESTCLASS.getDeclaredMethods()[0]));
    public void testFields () throws Exception {
        Collection fields = index.getFields (TESTATTRIBUTE);
        System.out.println (fields);
        assertEquals (1, fields.size ());
        assertTrue (fields.contains (TESTCLASS.getDeclaredFields()[0]));

Other Commons Attributes examples (source code examples)

Here is a short list of links related to this Commons Attributes AttributeIndexTestCase.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.