Skip to content

Instantly share code, notes, and snippets.

@vchimishuk
Last active December 7, 2017 09:58
Show Gist options
  • Save vchimishuk/ab8d07f60c78a08232aedcb270525875 to your computer and use it in GitHub Desktop.
Save vchimishuk/ab8d07f60c78a08232aedcb270525875 to your computer and use it in GitHub Desktop.
// 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