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