I am unit-testing a method performing some serialization operations. I intend to mock the serialization logic. The code is as below:
ObjectInputStream ois =          
        
You can specify a complete set of Expectations for a given set of interactions. From Behavior-based testing with JMockit:
A possible test for the doSomething() method could exercise the case where SomeCheckedException gets thrown, after an arbitrary number of successful iterations. Assuming that we want (for whatever reasons) to record a complete set of expectations for the interaction between these two classes, we might write the test below:
@Test
public void doSomethingHandlesSomeCheckedException() throws Exception
{
  new Expectations() {
     DependencyAbc abc;
     {
        new DependencyAbc(); // expect constructor
        abc.intReturningMethod(); result = 3;
        abc.stringReturningMethod();
        returns("str1", "str2");
        result = new SomeCheckedException();
     }
  };
  new UnitUnderTest().doSomething();
}