crazyboblee | abc4dd0 | 2007-02-01 01:44:36 +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 | */ |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 16 | |
| 17 | package com.google.inject; |
| 18 | |
| 19 | import junit.framework.TestCase; |
| 20 | |
| 21 | import java.util.List; |
| 22 | import java.util.Arrays; |
| 23 | |
| 24 | /** |
| 25 | * @author crazybob@google.com (Bob Lee) |
| 26 | */ |
| 27 | public class GenericInjectionTest extends TestCase { |
| 28 | |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 29 | public void testGenericInjection() throws CreationException { |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 30 | List<String> names = Arrays.asList("foo", "bar", "bob"); |
| 31 | ContainerBuilder builder = new ContainerBuilder(); |
crazyboblee | 0baa9fc | 2007-01-31 02:38:54 +0000 | [diff] [blame] | 32 | builder.bind(new TypeLiteral<List<String>>() {}).to(names); |
crazyboblee | 278ee4d | 2007-02-15 19:23:13 +0000 | [diff] [blame] | 33 | Container container = builder.create(); |
crazyboblee | 5746d5d | 2007-02-18 21:52:24 +0000 | [diff] [blame^] | 34 | Foo foo = container.getLocator(Foo.class).get(); |
crazyboblee | 63b592b | 2007-01-25 02:45:24 +0000 | [diff] [blame] | 35 | assertEquals(names, foo.names); |
| 36 | } |
| 37 | |
| 38 | static class Foo { |
| 39 | @Inject List<String> names; |
| 40 | } |
| 41 | } |