Created
May 22, 2012 11:24
-
-
Save awilmore/2768456 to your computer and use it in GitHub Desktop.
Populating Private Autowired Fields via Spring ReflectionTestUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Before; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import org.springframework.test.util.ReflectionTestUtils; | |
@RunWith(MockitoJUnitRunner.class) | |
public class ReflectionTestUtilsExampleTest { | |
@Mock private SomeDependency mockSomeDependency; | |
private SomeSortOfClass someSortOfClass; | |
@Before | |
public void init() { | |
initialiseTestClass() | |
} | |
private void initialiseTestClass() { | |
someSortOfClass = new SomeSortOfClass(); | |
ReflectionTestUtils.setField(abProfileInterceptor, "someDependency", mockSomeDependency); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment