Search in sources :

Example 76 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_withRange_lowerBoundLessThan0.

@Test
public void testSimpleMultipleNew_withRange_lowerBoundLessThan0() throws Exception {
    MyClass myClassMock1 = createMock(MyClass.class);
    try {
        expectNew(MyClass.class).andReturn(myClassMock1).times(-20, 2);
        fail("Should throw IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
        assertEquals("minimum must be >= 0", e.getMessage());
    }
}
Also used : MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 77 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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();
    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 78 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNewPrivate_ok.

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

Example 79 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testExpectNewButNoNewCallWasMade.

@Test
public void testExpectNewButNoNewCallWasMade() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).once();
    replayAll();
    try {
        tested.makeDate();
        verifyAll();
        fail("Should throw AssertionError!");
    } catch (AssertionError e) {
        assertTrue(e.getMessage().contains(MyClass.class.getName() + "(): expected: 1, actual: 0"));
    }
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 80 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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");
    replayAll();
    final String actual = tested.multipleNew();
    verifyAll();
    assertEquals("Hello World", actual);
}
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