1 /*
2  * Copyright (c) 2017 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.bugs;
6 
7 import org.junit.Before;
8 import org.junit.Test;
9 import org.mockito.Mock;
10 
11 import java.util.ArrayList;
12 import java.util.Collection;
13 
14 import static org.mockito.BDDMockito.given;
15 import static org.mockito.MockitoAnnotations.initMocks;
16 
17 /**
18  * This was an issue reported in #1174.
19  */
20 public class GenericsMockitoAnnotationsTest {
21 
22     @Mock
23     private TestCollectionSourceProvider testCollectionSourceProvider;
24 
25     @Test
should_not_throw_class_cast_exception()26     public void should_not_throw_class_cast_exception() {
27         given(testCollectionSourceProvider.getCollection(new ArrayList<Integer>())).willReturn(new ArrayList<Integer>());
28     }
29 
30     static class TestCollectionSourceProvider {
getCollection(T collection)31         <T extends Collection<E>, E> T getCollection(T collection) {
32             return collection;
33         }
34     }
35 
36     @Before
setUp()37     public void setUp() throws Exception {
38         initMocks(this);
39     }
40 }
41