001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.core.ext.typeinfo;
017:
018: import com.google.gwt.core.ext.TreeLogger;
019: import com.google.gwt.core.ext.UnableToCompleteException;
020: import com.google.gwt.core.ext.typeinfo.test.GenericClass;
021: import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
022:
023: import junit.framework.TestCase;
024:
025: /**
026: * Tests for {@link JGenericType}.
027: */
028: public class JGenericTypeTest extends TestCase {
029: private final boolean logToConsole = false;
030: private final ModuleContext moduleContext = new ModuleContext(
031: logToConsole ? new PrintWriterTreeLogger()
032: : TreeLogger.NULL,
033: "com.google.gwt.core.ext.typeinfo.TypeOracleTest");
034:
035: public JGenericTypeTest() throws UnableToCompleteException {
036: }
037:
038: /**
039: * Test method for
040: * {@link com.google.gwt.core.ext.typeinfo.JGenericType#getErasedType()}.
041: *
042: * @throws NotFoundException
043: */
044: public void testGetErasedType() throws NotFoundException {
045: JGenericType genericClass = getTestType();
046:
047: assertEquals(genericClass.getRawType(), genericClass
048: .getErasedType());
049: }
050:
051: /**
052: * Test method for
053: * {@link com.google.gwt.core.ext.typeinfo.JGenericType#getRawType()}.
054: *
055: * @throws NotFoundException
056: */
057: public void testGetRawType() throws NotFoundException {
058: JGenericType genericClass = getTestType();
059:
060: JDelegatingClassTypeTestBase.validateTypeSubstitution(
061: genericClass, genericClass.getRawType(),
062: new Substitution() {
063: public JType getSubstitution(JType type) {
064: return type.getErasedType();
065: }
066: });
067: }
068:
069: /**
070: * Test method for {@link
071: * com.google.gwt.core.ext.typeinfo.JGenericType#getTypeParameters()}.
072: *
073: * @throws NotFoundException
074: */
075: public void testGetTypeParameters() throws NotFoundException {
076: JGenericType genericType = getTestType();
077: JTypeParameter[] typeParameters = genericType
078: .getTypeParameters();
079:
080: assertEquals(1, typeParameters.length);
081:
082: JTypeParameter typeParameter = typeParameters[0];
083: assertEquals("T", typeParameter.getName());
084:
085: JBound bound = typeParameter.getBounds();
086: assertNotNull(bound.isUpperBound());
087:
088: JClassType[] bounds = bound.getBounds();
089: assertEquals(1, bounds.length);
090: assertEquals(moduleContext.getOracle().getJavaLangObject(),
091: bounds[0]);
092: }
093:
094: /**
095: * Returns the generic version of {@link GenericClass}.
096: */
097: protected JGenericType getTestType() throws NotFoundException {
098: JClassType type = moduleContext.getOracle().getType(
099: GenericClass.class.getName());
100: JGenericType genericType = type.isGenericType();
101: assertNotNull(genericType);
102: return genericType;
103: }
104: }
|