01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package com.google.inject;
16:
17: import junit.framework.TestCase;
18:
19: import java.util.List;
20: import java.lang.reflect.Type;
21:
22: /**
23: * @author crazybob@google.com (Bob Lee)
24: */
25: public class TypeLiteralTest extends TestCase {
26:
27: public void testWithParameterizedTypeImpl() {
28: TypeLiteral<List<String>> a = new TypeLiteral<List<String>>() {
29: };
30: TypeLiteral<List<String>> b = new TypeLiteral<List<String>>(
31: new TypeWithArgument(List.class, String.class)) {
32: };
33: assertEquals(a, b);
34: }
35:
36: public void testEquality() {
37: TypeLiteral<List<String>> t1 = new TypeLiteral<List<String>>() {
38: };
39: TypeLiteral<List<String>> t2 = new TypeLiteral<List<String>>() {
40: };
41: TypeLiteral<List<Integer>> t3 = new TypeLiteral<List<Integer>>() {
42: };
43: TypeLiteral<String> t4 = new TypeLiteral<String>() {
44: };
45:
46: assertEquals(t1, t2);
47: assertEquals(t2, t1);
48:
49: assertFalse(t2.equals(t3));
50: assertFalse(t3.equals(t2));
51:
52: assertFalse(t2.equals(t4));
53: assertFalse(t4.equals(t2));
54:
55: TypeLiteral<String> t5 = TypeLiteral.get(String.class);
56: assertEquals(t4, t5);
57: }
58:
59: public void testMissingTypeParameter() {
60: try {
61: new TypeLiteral() {
62: };
63: fail();
64: } catch (RuntimeException e) { /* expected */
65: }
66: }
67:
68: public void testTypesInvolvingArraysForEquality() {
69: TypeLiteral<String[]> stringArray = new TypeLiteral<String[]>() {
70: };
71: assertEquals(stringArray, new TypeLiteral<String[]>() {
72: });
73:
74: TypeLiteral<List<String[]>> listOfStringArray = new TypeLiteral<List<String[]>>() {
75: };
76: assertEquals(listOfStringArray,
77: new TypeLiteral<List<String[]>>() {
78: });
79: }
80: }
|