Search in sources :

Example 61 with MyClass

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

the class WhenNewCases method testSimpleMultipleNew_withAtLeastOnce.

@Test
public void testSimpleMultipleNew_withAtLeastOnce() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = mock(MyClass.class);
    whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
    tested.simpleMultipleNew();
    verifyNew(MyClass.class, atLeastOnce()).withNoArguments();
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 62 with MyClass

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

the class WhenNewCases method testExpectNewButNoNewCallWasMade.

@Test
public void testExpectNewButNoNewCallWasMade() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = mock(MyClass.class);
    whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
    tested.makeDate();
    try {
        verifyNew(MyClass.class).withNoArguments();
        fail("Should throw AssertionError!");
    } catch (AssertionError e) {
        assertEquals("Wanted but not invoked samples.newmocking.MyClass();\nActually, there were zero interactions with this mock.", e.getMessage());
    }
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 63 with MyClass

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

the class WhenNewCases method testSimpleSingleNew_withAtLeastOnce.

@Test
public void testSimpleSingleNew_withAtLeastOnce() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = mock(MyClass.class);
    whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
    tested.simpleSingleNew();
    verifyNew(MyClass.class, atLeastOnce()).withNoArguments();
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 64 with MyClass

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

the class ExpectNewDemo method multipleNew.

public String multipleNew() {
    MyClass myClass1 = new MyClass();
    MyClass myClass2 = new MyClass();
    final String message1 = myClass1.getMessage();
    final String message2 = myClass2.getMessage();
    return message1 + message2;
}
Also used : MyClass(samples.newmocking.MyClass)

Example 65 with MyClass

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

the class ExpectNewDemo method invokeVoidMethod.

public void invokeVoidMethod() {
    MyClass myClass = new MyClass();
    myClass.voidMethod();
}
Also used : MyClass(samples.newmocking.MyClass)

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