Search in sources :

Example 86 with MyClass

use of samples.newmocking.MyClass in project powermock by powermock.

the class ExpectNewCases method testGetMessageWithArgument.

@Test
public void testGetMessageWithArgument() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    String expected = "Hello altered World";
    expect(myClassMock.getMessage("test")).andReturn("Hello altered World");
    replay(myClassMock, MyClass.class);
    String actual = tested.getMessageWithArgument();
    verify(myClassMock, MyClass.class);
    assertEquals("Expected and actual did not match", expected, actual);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test)

Example 87 with MyClass

use of samples.newmocking.MyClass in project powermock by powermock.

the class ExpectNewCases method testSimpleMultipleNew_anyTimes.

@Test
public void testSimpleMultipleNew_anyTimes() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).anyTimes();
    replay(myClassMock1, MyClass.class);
    tested.simpleMultipleNew();
    verify(myClassMock1, MyClass.class);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test)

Example 88 with MyClass

use of samples.newmocking.MyClass in project powermock by powermock.

the class ExpectNewCases method testGetMessage.

@Test
public void testGetMessage() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    String expected = "Hello altered World";
    expect(myClassMock.getMessage()).andReturn("Hello altered World");
    replay(myClassMock, MyClass.class);
    String actual = tested.getMessage();
    verify(myClassMock, MyClass.class);
    assertEquals("Expected and actual did not match", expected, actual);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test)

Example 89 with MyClass

use of samples.newmocking.MyClass in project powermock by powermock.

the class ExpectNewCases method testSimpleMultipleNew_withRange_OK.

@Test
public void testSimpleMultipleNew_withRange_OK() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).times(1, 5);
    replay(myClassMock1, MyClass.class);
    tested.simpleMultipleNew();
    verify(myClassMock1, MyClass.class);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test)

Example 90 with MyClass

use of samples.newmocking.MyClass in project powermock by powermock.

the class ExpectNewCases method testMultipleNew.

@Test
public void testMultipleNew() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    MyClass myClassMock2 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1);
    expectNew(MyClass.class).andReturn(myClassMock2);
    expect(myClassMock1.getMessage()).andReturn("Hello ");
    expect(myClassMock2.getMessage()).andReturn("World");
    replay(myClassMock1, myClassMock2, MyClass.class);
    final String actual = tested.multipleNew();
    verify(myClassMock1, myClassMock2, MyClass.class);
    assertEquals("Hello World", actual);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test)

Aggregations

MyClass (samples.newmocking.MyClass)93 Test (org.junit.Test)91 ExpectNewDemo (samples.expectnew.ExpectNewDemo)75 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 PrepareEverythingForTest (org.powermock.core.classloader.annotations.PrepareEverythingForTest)21 StupidNew (samples.newmocking.StupidNew)3 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)2