Last active
August 29, 2015 13:57
-
-
Save frickm/9503298 to your computer and use it in GitHub Desktop.
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
package my.fricke.stackoverflow; | |
import javax.inject.Inject; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.MockitoAnnotations; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import junit.framework.Assert; | |
import static org.mockito.Mockito.mock; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = MockInjectionTest.TestApp.class) | |
public class MockInjectionTest { | |
@Inject | |
public Blub blub; | |
@Inject | |
public BlubBlub blubblub; | |
@Configuration | |
public static class TestApp { | |
@Bean | |
Blub getBlub() { | |
return mock(Blub.class); | |
} | |
@Bean | |
BlubBlub getBlubBlub() { | |
return new BlubBlub(); | |
} | |
} | |
@Test | |
public void testBlub() { | |
Assert.assertNotNull(blub); | |
} | |
@Before | |
public void setup() { | |
MockitoAnnotations.initMocks(this); | |
} | |
// the classes | |
public static class Bla { | |
} | |
public static class Blub { | |
@Inject | |
public Bla bla; | |
} | |
private static class BlubBlub { | |
@Inject | |
public Blub blub; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment