blob: 43f4553bd896c9956e72dba0455dd3c8ffc41c7c [file] [log] [blame]
crazyboblee41bc8522006-12-08 07:06:55 +00001/**
2 * Copyright (C) 2006 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
17package com.google.inject;
18
19import junit.framework.TestCase;
20
21import java.util.List;
22
23/**
24 * @author crazybob@google.com (Bob Lee)
25 */
crazyboblee0baa9fc2007-01-31 02:38:54 +000026public class TypeLiteralTest extends TestCase {
crazyboblee41bc8522006-12-08 07:06:55 +000027
28 public void testEquality() {
crazyboblee0baa9fc2007-01-31 02:38:54 +000029 TypeLiteral<List<String>> t1 = new TypeLiteral<List<String>>() {};
30 TypeLiteral<List<String>> t2 = new TypeLiteral<List<String>>() {};
31 TypeLiteral<List<Integer>> t3 = new TypeLiteral<List<Integer>>() {};
32 TypeLiteral<String> t4 = new TypeLiteral<String>() {};
crazyboblee41bc8522006-12-08 07:06:55 +000033
34 assertEquals(t1, t2);
35 assertEquals(t2, t1);
36
37 assertFalse(t2.equals(t3));
38 assertFalse(t3.equals(t2));
39
40 assertFalse(t2.equals(t4));
41 assertFalse(t4.equals(t2));
42
crazyboblee0baa9fc2007-01-31 02:38:54 +000043 TypeLiteral<String> t5 = TypeLiteral.get(String.class);
crazyboblee41bc8522006-12-08 07:06:55 +000044 assertEquals(t4, t5);
45 }
46
47 public void testMissingTypeParameter() {
48 try {
crazyboblee0baa9fc2007-01-31 02:38:54 +000049 new TypeLiteral() {};
crazyboblee41bc8522006-12-08 07:06:55 +000050 fail();
51 } catch (RuntimeException e) { /* expected */ }
52 }
53}