gordonad / powermock

Automatically exported from code.google.com/p/powermock
0 stars 0 forks source link

New simple syntax for expecting new #161

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be possible to setup expectations to construction of new objects
like this:

expect(new File("mypath")).andReturn(fileMock);

This would work if the MockGateway does something like this on each
constructor call:

Class stateKlass =
Class.forName("powermock.extension.spi.PowerMockStateExtractor");
PowerMockStateExtractor  se = (PowerMockStateExtractor)
stateKlass.newInstance();

if(state.isInReplayState()) {
     // Replace call to new File with a mock object and expect the
invocation on the substitute
} else  if(inVerifyState) {
 .. 
} else {
  proceed(..);
}
EasyMock and Mockito extension must thus provide different implementations
of powermock.extension.spi.PowerMockStateExtractor.

This would only work if the test case is prepared for test as well.

Original issue reported on code.google.com by johan.ha...@gmail.com on 11 Sep 2009 at 12:56