001: // Copyright 2006 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.ioc.internal.util;
016:
017: import java.io.Serializable;
018: import java.util.List;
019:
020: import org.apache.tapestry.ioc.test.TestBase;
021: import org.testng.annotations.Test;
022:
023: /**
024: *
025: */
026: public class InheritanceSearchTest extends TestBase {
027:
028: @Test
029: public void remove_always_fails() {
030: try {
031: new InheritanceSearch(Object.class).remove();
032: unreachable();
033: } catch (UnsupportedOperationException ex) {
034:
035: }
036: }
037:
038: @Test
039: public void next_when_no_more() {
040: InheritanceSearch s = new InheritanceSearch(Object.class);
041:
042: assertSame(s.next(), Object.class);
043: assertFalse(s.hasNext());
044:
045: try {
046: s.next();
047: unreachable();
048: } catch (IllegalStateException ex) {
049:
050: }
051: }
052:
053: @Test
054: public void inheritance_of_object() {
055: check(Object.class, Object.class);
056: }
057:
058: @Test
059: public void inheritance_of_string() {
060: check(String.class, String.class, Serializable.class,
061: Comparable.class, CharSequence.class, Object.class);
062: }
063:
064: @Test
065: public void inheritance_of_an_interface() {
066: check(Comparable.class, Comparable.class, Object.class);
067: }
068:
069: @Test
070: public void inheritance_search_order_for_interfaces() {
071: check(FooBar.class, FooBar.class, Foo.class, Bar.class,
072: Object.class);
073: }
074:
075: @Test
076: public void inheritance_search_order_for_classes() {
077: check(FooBarImpl.class, FooBarImpl.class, FooImpl.class,
078: BarImpl.class, Bar.class, FooBar.class, Foo.class,
079: Object.class);
080:
081: }
082:
083: @Test
084: public void inheritance_of_primitive() {
085: check(long.class, long.class, Long.class, Number.class,
086: Comparable.class, Serializable.class, Object.class);
087: }
088:
089: @Test
090: public void inheritance_of_void() {
091: check(void.class, void.class, Object.class);
092: }
093:
094: @Test
095: public void inheritance_of_primitive_array() {
096: check(long[].class, long[].class, Cloneable.class,
097: Serializable.class, Object.class);
098: }
099:
100: @Test
101: public void inheritance_of_a_2d_primitive_array() {
102: check(int[][].class, int[][].class, Cloneable.class,
103: Serializable.class, Object.class);
104: }
105:
106: @Test
107: public void inheritance_of_an_object_array() {
108: check(String[].class, String[].class, Object[].class,
109: Cloneable.class, Serializable.class, Object.class);
110: }
111:
112: @Test
113: public void inheritance_of_a_2d_object_array() {
114: check(String[][].class, String[][].class, Object[].class,
115: Cloneable.class, Serializable.class, Object.class);
116: }
117:
118: private void check(Class searchClass, Class... expected) {
119: List<Class> list = CollectionFactory.newList();
120:
121: // This for loop is how the class is generally used:
122:
123: for (Class c : new InheritanceSearch(searchClass))
124: list.add(c);
125:
126: assertEquals(list.toArray(), expected);
127: }
128: }
|