Search in sources :

Example 71 with MyClass

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

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

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_withAtLeastOnce.

@Test
public void testSimpleMultipleNew_withAtLeastOnce() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    MyClass myClassMock1 = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
    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 73 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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");
    replayAll();
    String actual = tested.getMessageWithArgument();
    verifyAll();
    assertEquals("Expected and actual did not match", expected, actual);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 74 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testPreviousProblemsWithByteCodeManipulation.

@Test
public void testPreviousProblemsWithByteCodeManipulation() throws Exception {
    MyClass myClassMock1 = createMock(MyClass.class);
    expect(myClassMock1.getMessage()).andReturn("Hello");
    expect(myClassMock1.getMessage()).andReturn("World");
    replayAll();
    assertEquals("Hello", myClassMock1.getMessage());
    assertEquals("World", myClassMock1.getMessage());
    verifyAll();
}
Also used : MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 75 with MyClass

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

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testGetMessage.

@PrepareEverythingForTest
@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");
    replayAll();
    String actual = tested.getMessage();
    verifyAll();
    assertEquals("Expected and actual did not match", expected, actual);
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) MyClass(samples.newmocking.MyClass) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest) 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