use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewDemoTest method testNewWithArrayVarArgsWhenFirstArgumentIsNullAndSubseqentArgumentsAreNotNull.
@Test
public void testNewWithArrayVarArgsWhenFirstArgumentIsNullAndSubseqentArgumentsAreNotNull() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = null;
final byte[] byteArrayTwo = new byte[] { 17 };
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.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewDemoTest method testNewWithArrayVarArgsAndMatchers.
@Test
public void testNewWithArrayVarArgsAndMatchers() 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, aryEq(byteArrayOne), aryEq(byteArrayTwo)).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getByteArrays()).andReturn(new byte[][] { byteArrayOne });
replay(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
byte[][] varArgs = tested.newVarArgsWithMatchers();
assertEquals(1, varArgs.length);
assertSame(byteArrayOne, varArgs[0]);
verify(VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class ExpectNewDemoTest method testNewWithArrayVarArgsWhenFirstArgumentIsNotNullButSubseqentArgumentsAreNull.
@Test
public void testNewWithArrayVarArgsWhenFirstArgumentIsNotNullButSubseqentArgumentsAreNull() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = new byte[] { 42 };
final byte[] byteArrayTwo = null;
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 ExpectNewDemoTest method testNewWithVarArgsConstructorWhenOneArgumentIsOfASubType.
@Test
public void testNewWithVarArgsConstructorWhenOneArgumentIsOfASubType() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
Service serviceMock = createMock(Service.class);
VarArgsConstructorDemo varArgsConstructorDemoMock = createMock(VarArgsConstructorDemo.class);
final Service serviceSubTypeInstance = new Service() {
@Override
public String getServiceMessage() {
return "message";
}
};
expectNew(VarArgsConstructorDemo.class, serviceSubTypeInstance, serviceMock).andReturn(varArgsConstructorDemoMock);
expect(varArgsConstructorDemoMock.getAllServices()).andReturn(new Service[] { serviceMock });
replay(serviceMock, VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
Service[] varArgs = tested.newVarArgs(serviceSubTypeInstance, serviceMock);
assertEquals(1, varArgs.length);
assertSame(serviceMock, varArgs[0]);
verify(serviceMock, VarArgsConstructorDemo.class, varArgsConstructorDemoMock);
}
use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.
the class WhenNewCases method testNewWithArrayVarArgs.
@Test
public void testNewWithArrayVarArgs() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);
final byte[] byteArrayOne = new byte[] { 42 };
final byte[] byteArrayTwo = new byte[] { 17 };
whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo).thenReturn(varArgsConstructorDemoMock);
when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayOne });
byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
assertEquals(1, varArgs.length);
assertSame(byteArrayOne, varArgs[0]);
verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
}
Aggregations