use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewCases method testSimpleMultipleNewPrivate_ok.
@Test
public void testSimpleMultipleNewPrivate_ok() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(3);
replay(myClassMock1, MyClass.class);
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewCases method testNewWithArrayVarArgsWhenAllArgumentsAreNull.
@Test
public void testNewWithArrayVarArgsWhenAllArgumentsAreNull() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = null;
final byte[] byteArrayTwo = null;
expectNew(VarArgsConstructorDemo.class, byteArrayOne, byteArrayTwo).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getByteArrays()).andReturn(new byte[][] { byteArrayTwo });
replay(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
assertEquals(1, varArgs.length);
assertSame(byteArrayTwo, varArgs[0]);
verify(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewCases method testSimpleMultipleNewPrivate_tooManyTimesExpected.
@Test
public void testSimpleMultipleNewPrivate_tooManyTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(4);
replay(myClassMock1, MyClass.class);
try {
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
verify(myClassMock1, MyClass.class);
fail("Should throw an exception!.");
} catch (AssertionError e) {
assertEquals("\n Expectation failure on verify:" + "\n samples.newmocking.MyClass(): expected: 4, actual: 3", e.getMessage());
}
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewCases method testSimpleMultipleNew_withAtLeastOnce.
@Test
public void testSimpleMultipleNew_withAtLeastOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewCases method testSimpleSingleNew_withAtLeastOnce.
@Test
public void testSimpleSingleNew_withAtLeastOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
replay(myClassMock1, MyClass.class);
tested.simpleSingleNew();
verify(myClassMock1, MyClass.class);
}
Aggregations