Jeet
Jeet

Reputation: 167

How to mock a method in JMockit?

For unit testing purpose i need to mock a method which take byte [] as argument.The output will be feed the argument. I want the output as per my requirement. So can anybody help me out with the mocking.

Upvotes: 0

Views: 155

Answers (1)

Rogério
Rogério

Reputation: 16380

Use a Delegate object when recording the expectation on the method with a byte[] parameter. Here is an example:

@Test
public void someTestMethod(@Mocked final DependencyAbc abc)
{
    new NonStrictExpectations() {{
        abc.someMethod((byte[]) any);
        result = new Delegate() {
            byte[] delegate(byte[] b) { return b; }
        };
    }};

    new UnitUnderTest(abc).doSomething();
}

Upvotes: 1

Related Questions