1 /* 2 * Copyright (c) 2007 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.junit.Assert.assertNotSame; 8 9 import java.util.*; 10 11 import org.junit.Test; 12 import org.junit.runner.RunWith; 13 import org.mockito.InjectMocks; 14 import org.mockito.Mock; 15 import org.mockito.Spy; 16 import org.mockito.junit.MockitoJUnitRunner; 17 18 // issue 262 19 @RunWith(MockitoJUnitRunner.class) 20 public class ShouldNotTryToInjectInFinalOrStaticFieldsTest { 21 22 public static class ExampleService { 23 public static final List<String> CONSTANTS = Arrays.asList("c1", "c1"); 24 public final Set<String> aSet = new HashSet<String>(); 25 } 26 27 @Spy private List<String> unrelatedList = new ArrayList<String>(); 28 @Mock private Set<String> unrelatedSet; 29 30 @InjectMocks private ExampleService exampleService = new ExampleService(); 31 32 @Test dont_fail_with_CONSTANTS()33 public void dont_fail_with_CONSTANTS() throws Exception {} 34 35 @Test dont_inject_in_final()36 public void dont_inject_in_final() { 37 assertNotSame(unrelatedSet, exampleService.aSet); 38 } 39 } 40