• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.injection;
6 
7 import static org.assertj.core.api.Assertions.assertThat;
8 import static org.junit.Assert.assertSame;
9 
10 import java.util.HashMap;
11 import java.util.Map;
12 
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.InjectMocks;
16 import org.mockito.Mock;
17 import org.mockito.junit.MockitoJUnitRunner;
18 
19 @RunWith(MockitoJUnitRunner.class)
20 public class Issue353InjectionMightNotHappenInCertainConfigurationTest {
21     @Mock Map<String, String> stringString_that_matches_field;
22     @Mock Map<String, Integer> mockStringInteger_was_not_injected;
23     @InjectMocks FooService fooService;
24 
25     @Test
26     public void
when_identical_types_and_the_correct_mock_name_is_greater_than_the_non_matching_name_then_injection_occurs_only_on_the_named_one()27             when_identical_types_and_the_correct_mock_name_is_greater_than_the_non_matching_name_then_injection_occurs_only_on_the_named_one() {
28         assertThat(
29                         "stringString_that_matches_field"
30                                 .compareTo("mockStringInteger_was_not_injected"))
31                 .isGreaterThanOrEqualTo(1);
32 
33         assertSame(stringString_that_matches_field, fooService.stringString_that_matches_field);
34         assertSame(mockStringInteger_was_not_injected, fooService.stringInteger_field);
35     }
36 
37     public static class FooService {
38         Map<String, Integer> stringInteger_field = new HashMap<String, Integer>();
39         Map<String, String> stringString_that_matches_field = new HashMap<String, String>();
40     }
41 }
42