crazyboblee | 41bc852 | 2006-12-08 07:06:55 +0000 | [diff] [blame] | 1 | /** |
| 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 | |
| 17 | package com.google.inject; |
| 18 | |
| 19 | import junit.framework.TestCase; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
| 23 | /** |
| 24 | * @author crazybob@google.com (Bob Lee) |
| 25 | */ |
crazyboblee | 0baa9fc | 2007-01-31 02:38:54 +0000 | [diff] [blame] | 26 | public class TypeLiteralTest extends TestCase { |
crazyboblee | 41bc852 | 2006-12-08 07:06:55 +0000 | [diff] [blame] | 27 | |
| 28 | public void testEquality() { |
crazyboblee | 0baa9fc | 2007-01-31 02:38:54 +0000 | [diff] [blame] | 29 | 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>() {}; |
crazyboblee | 41bc852 | 2006-12-08 07:06:55 +0000 | [diff] [blame] | 33 | |
| 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 | |
crazyboblee | 0baa9fc | 2007-01-31 02:38:54 +0000 | [diff] [blame] | 43 | TypeLiteral<String> t5 = TypeLiteral.get(String.class); |
crazyboblee | 41bc852 | 2006-12-08 07:06:55 +0000 | [diff] [blame] | 44 | assertEquals(t4, t5); |
| 45 | } |
| 46 | |
| 47 | public void testMissingTypeParameter() { |
| 48 | try { |
crazyboblee | 0baa9fc | 2007-01-31 02:38:54 +0000 | [diff] [blame] | 49 | new TypeLiteral() {}; |
crazyboblee | 41bc852 | 2006-12-08 07:06:55 +0000 | [diff] [blame] | 50 | fail(); |
| 51 | } catch (RuntimeException e) { /* expected */ } |
| 52 | } |
| 53 | } |