1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6 package org.mockitousage.bugs.injection; 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.Spy; 13 import org.mockito.junit.MockitoJUnitRunner; 14 15 import java.util.*; 16 17 import static org.junit.Assert.assertNotSame; 18 19 // issue 262 20 @RunWith(MockitoJUnitRunner.class) 21 public class ShouldNotTryToInjectInFinalOrStaticFieldsTest { 22 23 public static class ExampleService { 24 public static final List<String> CONSTANTS = Arrays.asList("c1", "c1"); 25 public final Set<String> aSet = new HashSet<String>(); 26 } 27 28 @Spy private List<String> unrelatedList = new ArrayList<String>(); 29 @Mock private Set<String> unrelatedSet; 30 31 @InjectMocks private ExampleService exampleService = new ExampleService(); 32 33 @Test dont_fail_with_CONSTANTS()34 public void dont_fail_with_CONSTANTS() throws Exception { 35 } 36 37 @Test dont_inject_in_final()38 public void dont_inject_in_final() { 39 assertNotSame(unrelatedSet, exampleService.aSet); 40 } 41 42 } 43