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 java.lang.annotation.Retention;
18: import static java.lang.annotation.RetentionPolicy.RUNTIME;
19: import java.lang.reflect.Method;
20: import java.lang.reflect.Type;
21: import java.util.List;
22: import junit.framework.TestCase;
23:
24: /**
25: * @author crazybob@google.com (Bob Lee)
26: */
27: public class KeyTest extends TestCase {
28:
29: public void foo(List<String> a, List<String> b) {
30: }
31:
32: @Retention(RUNTIME)
33: @BindingAnnotation
34: @interface Foo {
35: }
36:
37: public void testOfType() {
38: Key<Object> k = Key.get(Object.class, Foo.class);
39: Key<Integer> ki = k.ofType(int.class);
40: assertEquals(int.class, ki.getRawType());
41: assertEquals(Foo.class, ki.getAnnotationType());
42: }
43:
44: public void testEquality() {
45: assertEquals(new Key<List<String>>(Foo.class) {
46: }, Key.get(new TypeLiteral<List<String>>() {
47: }, Foo.class));
48: }
49:
50: public void testTypeEquality() throws Exception {
51: Method m = getClass().getMethod("foo", List.class, List.class);
52: Type[] types = m.getGenericParameterTypes();
53: assertEquals(types[0], types[1]);
54: Key<List<String>> k = new Key<List<String>>() {
55: };
56: assertEquals(types[0], k.getTypeLiteral().getType());
57: assertFalse(types[0].equals(new Key<List<Integer>>() {
58: }.getTypeLiteral().getType()));
59: }
60: }
|