forked from ringcentral/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance spock.xsd to support creation on a bean reference for partiy
with DetachedMockFactory
- Loading branch information
Taylor Wicksell
committed
Mar 21, 2017
1 parent
7e5acd1
commit 8c8ea9f
Showing
6 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
spock-spring/src/main/java/org/spockframework/spring/xml/SpockSpyBeanPostProcessor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.spockframework.spring.xml; | ||
|
||
import java.util.Collections; | ||
|
||
import org.spockframework.mock.MockNature; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
|
||
import spock.mock.DetachedMockFactory; | ||
|
||
public class SpockSpyBeanPostProcessor implements BeanPostProcessor { | ||
|
||
private final String beanName; | ||
|
||
public SpockSpyBeanPostProcessor(String beanName) { | ||
this.beanName = beanName; | ||
} | ||
|
||
@Override | ||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | ||
return bean; | ||
} | ||
|
||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
if (this.beanName.equals(beanName)) { | ||
return new DetachedMockFactory().createMock(beanName, bean, MockNature.SPY, | ||
Collections.<String, Object>emptyMap()); | ||
} else { | ||
return bean; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...k-spring/src/main/java/org/spockframework/spring/xml/WrapWithSpyBeanDefinitionParser.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.spockframework.spring.xml; | ||
|
||
import org.springframework.beans.factory.support.BeanDefinitionBuilder; | ||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; | ||
import org.w3c.dom.Element; | ||
|
||
public class WrapWithSpyBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { | ||
|
||
@Override | ||
protected Class<?> getBeanClass(Element element) { | ||
return SpockSpyBeanPostProcessor.class; | ||
} | ||
|
||
@Override | ||
protected void doParse(Element element, BeanDefinitionBuilder builder) { | ||
builder.addConstructorArgValue(element.getAttribute("ref")); | ||
} | ||
|
||
@Override | ||
protected boolean shouldGenerateIdAsFallback() { | ||
return true; | ||
} | ||
} |
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
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
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