Search in sources :

Example 16 with VarArgsConstructorDemo

use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.

the class WhenNewCases method testNewWithArrayVarArgsWhenFirstArgumentIsNullAndSubseqentArgumentsAreNotNull.

@Test
public void testNewWithArrayVarArgsWhenFirstArgumentIsNullAndSubseqentArgumentsAreNotNull() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);
    final byte[] byteArrayOne = null;
    final byte[] byteArrayTwo = new byte[] { 17 };
    whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo).thenReturn(varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayTwo });
    byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
    assertEquals(1, varArgs.length);
    assertSame(byteArrayTwo, varArgs[0]);
    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) VarArgsConstructorDemo(samples.expectnew.VarArgsConstructorDemo) SimpleVarArgsConstructorDemo(samples.expectnew.SimpleVarArgsConstructorDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with VarArgsConstructorDemo

use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.

the class WhenNewCases method testNewWithVarArgsConstructorWhenOneArgumentIsOfASubType.

@Test
public void testNewWithVarArgsConstructorWhenOneArgumentIsOfASubType() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    Service serviceMock = mock(Service.class);
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);
    final Service serviceSubTypeInstance = new Service() {

        public String getServiceMessage() {
            return "message";
        }
    };
    whenNew(VarArgsConstructorDemo.class).withArguments(serviceSubTypeInstance, serviceMock).thenReturn(varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getAllServices()).thenReturn(new Service[] { serviceMock });
    Service[] varArgs = tested.newVarArgs(serviceSubTypeInstance, serviceMock);
    assertEquals(1, varArgs.length);
    assertSame(serviceMock, varArgs[0]);
    verifyNew(VarArgsConstructorDemo.class).withArguments(serviceSubTypeInstance, serviceMock);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) VarArgsConstructorDemo(samples.expectnew.VarArgsConstructorDemo) SimpleVarArgsConstructorDemo(samples.expectnew.SimpleVarArgsConstructorDemo) Service(samples.Service) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with VarArgsConstructorDemo

use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.

the class ExpectNewDemoTest 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);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) VarArgsConstructorDemo(samples.expectnew.VarArgsConstructorDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with VarArgsConstructorDemo

use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.

the class ExpectNewDemoTest 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);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) VarArgsConstructorDemo(samples.expectnew.VarArgsConstructorDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with VarArgsConstructorDemo

use of samples.expectnew.VarArgsConstructorDemo in project powermock by powermock.

the class ExpectNewDemoTest 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);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) VarArgsConstructorDemo(samples.expectnew.VarArgsConstructorDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)33 ExpectNewDemo (samples.expectnew.ExpectNewDemo)33 VarArgsConstructorDemo (samples.expectnew.VarArgsConstructorDemo)33 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 SimpleVarArgsConstructorDemo (samples.expectnew.SimpleVarArgsConstructorDemo)9 PrepareEverythingForTest (org.powermock.core.classloader.annotations.PrepareEverythingForTest)8 Service (samples.Service)4