0

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.

Jeet
  • 157
  • 2
  • 2
  • 4

1 Answers1

1

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();
}
Rogério
  • 16,171
  • 2
  • 50
  • 63