1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.reflect;
18
19 import com.google.common.testing.EqualsTester;
20 import com.google.common.testing.NullPointerTester;
21
22 import junit.framework.TestCase;
23
24 import java.lang.reflect.Method;
25 import java.lang.reflect.TypeVariable;
26
27
28
29
30
31
32 public class TypeParameterTest extends TestCase {
33
34 public <T> void testCaptureTypeParameter() throws Exception {
35 TypeVariable<?> variable = new TypeParameter<T>() {}.typeVariable;
36 TypeVariable<?> expected = TypeParameterTest.class
37 .getDeclaredMethod("testCaptureTypeParameter")
38 .getTypeParameters()[0];
39 assertEquals(expected, variable);
40 }
41
42 public void testConcreteTypeRejected() {
43 try {
44 new TypeParameter<String>() {};
45 fail();
46 } catch (IllegalArgumentException expected) {}
47 }
48
49 public <A, B> void testEquals() throws Exception {
50 Method method = TypeParameterTest.class.getDeclaredMethod("testEquals");
51 new EqualsTester()
52 .addEqualityGroup(
53 new TypeParameter<A>() {}, new TypeParameter<A>() {})
54 .addEqualityGroup(new TypeParameter<B>() {})
55 .testEquals();
56 }
57
58 public void testNullPointers() {
59 new NullPointerTester().testAllPublicStaticMethods(TypeParameter.class);
60 }
61 }