I have a test class, and have created a java config class to use with this class.. But im having issues as other tests seem to throw up found two instances of bean in configuration...
my test class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=TestConfiguration.class)
public class ListenerTest {
// various tests.. just basic stuff..
}
@Configuration
public class TestConfiguration {
@Bean
public MyListsner ListenerImpl() {
return Mockito.mock(MyListsner .class);
}
}
Now for this test class passes fine when i use a mock as above. My other test classes seem to fail and they are as follows:
test class which fails...
This class throws the error
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=GeneratorTestConfiguration.class)
@Transactional
public class GeneratorTest {
// various tests
}
Main config
@Configuration
@Import({
BaseConfiguration.class,
CoreBaseConfiguration.class
})
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@EnableTransactionManagement(proxyTargetClass = true)
@EnableJpaRepositories(basePackages={
"com.persistence.repository"
})
@ComponentScan({ // where the components are
"com.tests"
})
public class GeneratorTestConfiguration {
}
I dont know why, when i add listener mock to the above class ListenerTest, the toher tests fail, as im being specific in those classes to use the relevant configuration when autowiring.