[ 
https://issues.apache.org/jira/browse/DELTASPIKE-588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14000775#comment-14000775
 ] 

Gerhard Petracek edited comment on DELTASPIKE-588 at 5/17/14 12:40 PM:
-----------------------------------------------------------------------

mocking partial beans requires something like:

{code}
    public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable
    {
        if (isMockedMethod(method))
        {
            return method.invoke(this, args);
        }
        //...
    }

    private boolean isMockedMethod(Method method)
    {
        try
        {
            return getClass().getDeclaredMethod(method.getName(), 
method.getParameterTypes()) != null;
        }
        catch (NoSuchMethodException e)
        {
            return false;
        }
    }
{code}

in the InvocationHandler.

The mocked InvocationHandler needs to be something like:

{code}
@Typed()
public class MockedPartialBean extends CustomPartialBeanHandler implements 
PartialBean
{
    //mocked method implementations
}
{code}


was (Author: gpetracek):
mocking partial beans requires something like:

{code}
    public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable
    {
        if (isMockedMethod(method))
        {
            return method.invoke(this, args);
        }
        //...
    }

    private boolean isMockedMethod(Method method)
    {
        try
        {
            return getClass().getDeclaredMethod(method.getName(), 
method.getParameterTypes()) != null;
        }
        catch (NoSuchMethodException e)
        {
            return false;
        }
    }
{code}

in the InvocationHandler.

> Repositories from Data module should be deactivatable
> -----------------------------------------------------
>
>                 Key: DELTASPIKE-588
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-588
>             Project: DeltaSpike
>          Issue Type: Improvement
>          Components: Data-Module
>            Reporter: Karl Kildén
>            Assignee: Thomas Hug
>            Priority: Minor
>
> Unit testing with Test-Control is great. However since you don't control the 
> actual implementation of the Repositories from data-module they are to hard 
> to mock away.
> Either provide a built in project stage for this purpose -> 
> ProjectStage.MockFriendlyUnitTest or make it Deactivatable like other 
> components are.
> The end user would benefit a lot from being able to mock away repositories in 
> certain unit tests.  



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to