1 package org.mockitousage.bugs.injection; 2 3 4 import org.junit.Test; 5 import org.junit.runner.RunWith; 6 import org.mockito.InjectMocks; 7 import org.mockito.Mock; 8 import org.mockito.junit.MockitoJUnitRunner; 9 10 import java.util.HashMap; 11 import java.util.Map; 12 13 import static org.assertj.core.api.Assertions.assertThat; 14 import static org.junit.Assert.assertSame; 15 16 @RunWith(MockitoJUnitRunner.class) 17 public class Issue353InjectionMightNotHappenInCertainConfigurationTest { 18 @Mock Map<String, String> stringString_that_matches_field; 19 @Mock Map<String, Integer> mockStringInteger_was_not_injected; 20 @InjectMocks FooService fooService; 21 22 @Test when_identical_types_and_the_correct_mock_name_is_greater_than_the_non_matching_name_then_injection_occurs_only_on_the_named_one()23 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() { 24 assertThat("stringString_that_matches_field".compareTo("mockStringInteger_was_not_injected")).isGreaterThanOrEqualTo(1); 25 26 assertSame(stringString_that_matches_field, fooService.stringString_that_matches_field); 27 assertSame(mockStringInteger_was_not_injected, fooService.stringInteger_field); 28 } 29 30 public static class FooService { 31 Map<String, Integer> stringInteger_field = new HashMap<String, Integer>(); 32 Map<String, String> stringString_that_matches_field = new HashMap<String, String>(); 33 } 34 35 } 36