Commits

Anonymous committed 7b3d061

auto autowiring #refs #14

Comments (0)

Files changed (3)

springockito-annotations/src/main/java/org/kubek2k/springockito/annotations/SpringockitoContextLoader.java

 package org.kubek2k.springockito.annotations;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
+import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
 import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.test.context.support.GenericXmlContextLoader;
 
     @Override
     protected void customizeContext(GenericApplicationContext context) {
         super.customizeContext(context);
+
+        context.registerBeanDefinition("springockitoAutowiredBeanPostProcessor", BeanDefinitionBuilder.genericBeanDefinition(AutowiredAnnotationBeanPostProcessor.class)
+                .addPropertyValue("autowiredAnnotationTypes", new HashSet<Class>(Arrays.asList(ReplaceWithMock.class, WrapWithSpy.class)))
+                .getBeanDefinition());
+
         registerMocks(context, mockedBeans);
         registerSpies(context, spiedBeans);
     }

springockito-annotations/src/test/java/org/kubek2k/springockito/annotations/SpringockitoAnnotationsComponentScanMockAutoAutowiringIntegrationTest.java

+package org.kubek2k.springockito.annotations;
+
+import org.mockito.Answers;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.verify;
+
+@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:/componentScanMockContext.xml")
+public class SpringockitoAnnotationsComponentScanMockAutoAutowiringIntegrationTest extends AbstractTestNGSpringContextTests {
+
+    @ReplaceWithMock(extraInterfaces = {Runnable.class}, defaultAnswer = Answers.RETURNS_MOCKS)
+    private InnerBean innerBean;
+
+    @Test
+    public void shouldAutoAutowireMock() {
+        org.testng.Assert.assertNotNull(innerBean);
+    }
+
+}

springockito-annotations/src/test/java/org/kubek2k/springockito/annotations/SpringockitoAnnotationsComponentScanSpyAutoAutowiringIntegrationTest.java

+package org.kubek2k.springockito.annotations;
+
+import org.mockito.Answers;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.annotations.Test;
+
+@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:/componentScanMockContext.xml")
+public class SpringockitoAnnotationsComponentScanSpyAutoAutowiringIntegrationTest extends AbstractTestNGSpringContextTests {
+
+    @WrapWithSpy
+    private InnerBean innerBean;
+
+    @Test
+    public void shouldAutoAutowireSpy() {
+        org.testng.Assert.assertNotNull(innerBean);
+    }
+
+}