Last active
December 7, 2017 09:58
-
-
Save vchimishuk/ab8d07f60c78a08232aedcb270525875 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Main configuration in src/main/java | |
| @Configuration | |
| public class MainConfig { | |
| @Bean | |
| @Profile("default") | |
| public Ticker ticker() { return new Ticker(); } | |
| @Bean | |
| public Foo foo(Ticker ticker) { return new Foo(ticker); } // 1. | |
| } | |
| // Test configuration in src/test/java | |
| @Configuration | |
| public class TestConfig { | |
| @Bean | |
| @Profile("test") | |
| public Ticker ticker() { return new TestTicker(); } | |
| } | |
| // Test class. | |
| @ActiveProfiles("test") | |
| public class FooTest { | |
| @Autowired | |
| private Ticker ticker; | |
| @Test | |
| public void test() { | |
| when(ticker.read()).thenReturn(1234L); // | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment