use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewCases method testNewWithArrayVarArgsWhenFirstArgumentIsNullSecondArgumentIsNotNullAndThirdArgumentIsNull.
@Test
public void testNewWithArrayVarArgsWhenFirstArgumentIsNullSecondArgumentIsNotNullAndThirdArgumentIsNull() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = null;
final byte[] byteArrayTwo = new byte[] { 42 };
final byte[] byteArrayThree = null;
expectNew(VarArgsConstructorDemo.class, byteArrayOne, byteArrayTwo, byteArrayThree).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getByteArrays()).andReturn(new byte[][] { byteArrayTwo });
replay(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo, byteArrayThree);
assertEquals(1, varArgs.length);
assertSame(byteArrayTwo, varArgs[0]);
verify(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewCases method testNewWithArrayVarArgs.
@Test
public void testNewWithArrayVarArgs() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = new byte[] { 42 };
final byte[] byteArrayTwo = new byte[] { 17 };
expectNew(VarArgsConstructorDemo.class, byteArrayOne, byteArrayTwo).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getByteArrays()).andReturn(new byte[][] { byteArrayOne });
replay(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
assertEquals(1, varArgs.length);
assertSame(byteArrayOne, varArgs[0]);
verify(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewCases method testNewWithVarArgs.
@Test
public void testNewWithVarArgs() throws Exception {
final String firstString = "hello";
final String secondString = "world";
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
expectNew(VarArgsConstructorDemo.class, firstString, secondString).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getAllMessages()).andReturn(new String[] { firstString, secondString });
replay(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
String[] varArgs = tested.newVarArgs(firstString, secondString);
assertEquals(2, varArgs.length);
assertEquals(firstString, varArgs[0]);
assertEquals(secondString, varArgs[1]);
verify(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
Aggregations