I guess I missing something.
@Test(groups = {"unit"})
@PrepareForTest({Exchange.class, Message.class})
public class DynamicRouteProcessorTest extends BaseTest {
static final String MOCK_LOCATION = "location";
@Mock Exchange mockExchange;
@Mock Message mockMessage;
private DynamicRouteProcessor processor;
@BeforeMethod
public void setUp() {
processor = new DynamicRouteProcessor();
}
@Test
public void testProcessWithLocationHeader() throws Exception {
expect(mockExchange.getIn()).andReturn(mockMessage).anyTimes();
expect(mockMessage.getHeader(DynamicRouteProcessor.LOCATION_HEADER))
.andReturn(MOCK_LOCATION);
mockMessage.setHeader(DynamicRouteProcessor.BETFAIR_ROUTE, MOCK_LOCATION);
replayAll();
processor.process(mockExchange);
}
@Test
public void testProcessWithoutLocationHeader() throws Exception {
expect(mockExchange.getIn()).andReturn(mockMessage).anyTimes();
expect(mockMessage.getHeader(DynamicRouteProcessor.LOCATION_HEADER))
.andReturn(null);
mockMessage.setHeader(DynamicRouteProcessor.BETFAIR_ROUTE, MOCK_LOCATION);
replayAll();
processor.setLoc(MOCK_LOCATION);
processor.process(mockExchange);
}
}
This test fails with:
testProcessWithoutLocationHeader "no last call on a mock available"
And the reason here - mocks were not reinitialized for a second test. If I delete testProcessWithLocationHeader test, second one will pass.
What is wrong?
Alex