Search in sources :

Example 1 with PrivateMethodDemo

use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.

the class PrivateMethodDemoTest method testExpectPrivateMethodWithoutSpecifyingMethodName.

@Test
public void testExpectPrivateMethodWithoutSpecifyingMethodName() throws Exception {
    final String expected = "Hello world";
    PrivateMethodDemo tested = createPartialMock(PrivateMethodDemo.class, "doSayYear");
    expectPrivate(tested, 22, "name").andReturn(expected);
    replay(tested);
    assertEquals(expected, tested.sayYear("name", 22));
    verify(tested);
}
Also used : PrivateMethodDemo(samples.privatemocking.PrivateMethodDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with PrivateMethodDemo

use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.

the class PrivateMethodDemoTest method testExpectPrivateMethodWithoutSpecifyingMethodName_firstArgumentIsOfStringType.

@Test
public void testExpectPrivateMethodWithoutSpecifyingMethodName_firstArgumentIsOfStringType() throws Exception {
    final String expected = "Hello world";
    PrivateMethodDemo tested = createPartialMock(PrivateMethodDemo.class, "sayIt");
    expectPrivate(tested, (String) null, "firstName", " ", "lastName").andReturn(expected);
    replay(tested);
    assertEquals(expected, tested.enhancedSay("firstName", "lastName"));
    verify(tested);
}
Also used : PrivateMethodDemo(samples.privatemocking.PrivateMethodDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PrivateMethodDemo

use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.

the class PrivateMethodDemoTest method testExpectPrivateWithArrayMatcher.

@Test
public void testExpectPrivateWithArrayMatcher() throws Exception {
    PrivateMethodDemo tested = createPartialMock(PrivateMethodDemo.class, "doArrayInternal");
    expectPrivate(tested, "doArrayInternal", EasyMock.aryEq((Object[]) new String[] { "hello" }));
    replay(tested);
    tested.doArrayStuff("hello");
    verify(tested);
}
Also used : PrivateMethodDemo(samples.privatemocking.PrivateMethodDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PrivateMethodDemo

use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.

the class PrivateMethodDemoTest method testExpectPrivateWithObjectMatcher.

@Test
public void testExpectPrivateWithObjectMatcher() throws Exception {
    PrivateMethodDemo tested = createPartialMock(PrivateMethodDemo.class, "doObjectInternal");
    expectPrivate(tested, "doObjectInternal", EasyMock.isA(CharSequence.class));
    replay(tested);
    tested.doObjectStuff("hello");
    verify(tested);
}
Also used : PrivateMethodDemo(samples.privatemocking.PrivateMethodDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with PrivateMethodDemo

use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.

the class PrivateMethodDemoTest method testExpectPrivateMethodWithVarArgsParameters.

@Test
public void testExpectPrivateMethodWithVarArgsParameters() throws Exception {
    final String methodToExpect = "varArgsMethod";
    final int expected = 7;
    final int valueA = 2;
    final int valueB = 3;
    PrivateMethodDemo tested = createPartialMock(PrivateMethodDemo.class, methodToExpect);
    expectPrivate(tested, methodToExpect, valueA, valueB).andReturn(expected);
    replay(tested);
    assertEquals(expected, tested.invokeVarArgsMethod(valueA, valueB));
    verify(tested);
}
Also used : PrivateMethodDemo(samples.privatemocking.PrivateMethodDemo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)35 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 PrivateMethodDemo (samples.privatemocking.PrivateMethodDemo)35 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 File (java.io.File)1 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 FileDataSource (javax.activation.FileDataSource)1