Search in sources :

Example 11 with SuppressMethod

use of samples.suppressmethod.SuppressMethod in project powermock by powermock.

the class MemberModificationExampleTest method stubSingleMethodExample.

@Test
public void stubSingleMethodExample() throws Exception {
    final String expectedReturnValue = "new";
    stub(method(SuppressMethod.class, "getObject")).toReturn(expectedReturnValue);
    final SuppressMethod tested = new SuppressMethod();
    assertEquals(expectedReturnValue, tested.getObject());
    assertEquals(expectedReturnValue, tested.getObject());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with SuppressMethod

use of samples.suppressmethod.SuppressMethod in project powermock by powermock.

the class MemberModificationExampleTest method stubSingleMethodExample.

@Test
public void stubSingleMethodExample() throws Exception {
    final String expectedReturnValue = "new";
    stub(method(SuppressMethod.class, "getObject")).toReturn(expectedReturnValue);
    final SuppressMethod tested = new SuppressMethod();
    assertEquals(expectedReturnValue, tested.getObject());
    assertEquals(expectedReturnValue, tested.getObject());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with SuppressMethod

use of samples.suppressmethod.SuppressMethod in project powermock by powermock.

the class SuppressMethodTest method testGetDouble_parameter.

@Test
public void testGetDouble_parameter() throws Exception {
    suppress(method(SuppressMethod.class, "getDouble", new Class<?>[] { double.class }));
    SuppressMethod tested = new SuppressMethod();
    assertEquals("A method returning a double should return 0.0d after suppressing method code.", 0.0d, tested.getDouble(8.7d), 0);
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with SuppressMethod

use of samples.suppressmethod.SuppressMethod in project powermock by powermock.

the class StubMethodTest method test.

@Test
public void test() throws Exception {
    stubbing.enforceOn(stub(method(SuppressMethod.class, method.name())));
    final SuppressMethod tested = new SuppressMethod();
    Callable<?> methodInvocation = new Callable<Object>() {

        @Override
        public Object call() {
            return method.invokeOn(tested);
        }
    };
    stubbing.verify(methodInvocation);
    stubbing.verify(methodInvocation);
    stubbing.verify(methodInvocation);
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Callable(java.util.concurrent.Callable) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with SuppressMethod

use of samples.suppressmethod.SuppressMethod in project powermock by powermock.

the class MemberModificationExampleTest method changingReturnValueExample.

@Test
public void changingReturnValueExample() throws Exception {
    replace(method(SuppressMethod.class, "getObjectWithArgument")).with(new ReturnValueChangingInvocationHandler());
    final SuppressMethod tested = new SuppressMethod();
    assertThat(tested.getObjectWithArgument("don't do anything"), is(instanceOf(Object.class)));
    assertEquals("hello world", tested.getObjectWithArgument("make it a string"));
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)39 SuppressMethod (samples.suppressmethod.SuppressMethod)39 MethodNotFoundException (org.powermock.reflect.exceptions.MethodNotFoundException)2 TooManyMethodsFoundException (org.powermock.reflect.exceptions.TooManyMethodsFoundException)2 SuppressMethodExample (samples.suppressmethod.SuppressMethodExample)2 SuppressMethodParent (samples.suppressmethod.SuppressMethodParent)2 Callable (java.util.concurrent.Callable)1 Ignore (org.junit.Ignore)1 SuppressConstructorHierarchy (samples.suppressconstructor.SuppressConstructorHierarchy)1 SuppressField (samples.suppressfield.SuppressField)1