Home | History | Annotate | Download | only in internal
      1 /**
      2  * Copyright (C) 2010 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.inject.internal;
     18 
     19 import com.google.inject.TypeLiteral;
     20 
     21 import junit.framework.TestCase;
     22 
     23 import java.lang.reflect.Type;
     24 import java.util.Map;
     25 import java.util.Set;
     26 
     27 /**
     28  * @author schmitt (at) google.com (Peter Schmitt)
     29  */
     30 public class MoreTypesTest extends TestCase {
     31 
     32   public void testParameterizedTypeToString() {
     33     TypeLiteral<Inner<String>> innerString = new TypeLiteral<Inner<String>>(){};
     34     assertEquals("com.google.inject.internal.MoreTypesTest$Inner<java.lang.String>",
     35         MoreTypes.typeToString(innerString.getType()));
     36 
     37     TypeLiteral<Set<Inner<Integer>>> mapInnerInteger = new TypeLiteral<Set<Inner<Integer>>>() {};
     38     assertEquals("java.util.Set<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Integer>>",
     39         MoreTypes.typeToString(mapInnerInteger.getType()));
     40 
     41     TypeLiteral<Map<Inner<Long>, Set<Inner<Long>>>> mapInnerLongToSetInnerLong =
     42         new TypeLiteral<Map<Inner<Long>, Set<Inner<Long>>>>() {};
     43     assertEquals("java.util.Map<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Long>, "
     44             + "java.util.Set<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Long>>>",
     45         MoreTypes.typeToString(mapInnerLongToSetInnerLong.getType()));
     46   }
     47 
     48   public <T> void testEquals_typeVariable() throws Exception {
     49     Type type = getClass().getMethod("testEquals_typeVariable").getTypeParameters()[0];
     50     assertTrue(MoreTypes.equals(new TypeLiteral<T>() {}.getType(), type));
     51   }
     52 
     53   public static class Inner<T> {}
     54 }
     55