Search in sources :

Example 26 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_withRange_upperBoundLessThan0.

@Test
public void testSimpleMultipleNew_withRange_upperBoundLessThan0() throws Exception {
    MyClass myClassMock1 = createMock(MyClass.class);
    try {
        expectNew(MyClass.class).andReturn(myClassMock1).times(-1, -2);
        fail("Should throw IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("<="));
    }
}
Also used : MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 27 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_tooManyTimesExpected.

@Test
public void testSimpleMultipleNew_tooManyTimesExpected() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).times(4);
    replayAll();
    tested.simpleMultipleNew();
    try {
        verifyAll();
        fail("Should throw AssertionError.");
    } catch (AssertionError e) {
        assertEquals("\n  Expectation failure on verify:" + "\n    samples.newmocking.MyClass(): expected: 4, actual: 3", e.getMessage());
    }
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 28 with MyClass

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

the class ResetMockTest method assertManualResetWorks.

@Test
public void assertManualResetWorks() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");
    replayAll();
    String message = tested.getMessage();
    verifyAll();
    assertEquals("message", message);
    reset(myClassMock);
    reset(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");
    replayAll();
    message = tested.getMessage();
    verifyAll();
    assertEquals("message", message);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew.

@Test
public void testSimpleMultipleNew() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).times(3);
    replayAll();
    tested.simpleMultipleNew();
    verifyAll();
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 30 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleSingleNew_withAtLeastOnce.

@Test
public void testSimpleSingleNew_withAtLeastOnce() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
    replayAll();
    tested.simpleSingleNew();
    verifyAll();
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

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