Search in sources :

Example 21 with SuppressMethod

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

the class SpyTest method testSuppressMethodWhenObjectIsSpy.

@Test
public void testSuppressMethodWhenObjectIsSpy() throws Exception {
    suppress(method(SuppressMethod.class, "myMethod"));
    SuppressMethod tested = spy(new SuppressMethod());
    assertEquals(0, tested.myMethod());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with SuppressMethod

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

the class SpyTest method testSuppressMethodInParentOnlyWhenObjectIsSpy.

@Test
public void testSuppressMethodInParentOnlyWhenObjectIsSpy() throws Exception {
    suppress(method(SuppressMethodParent.class, "myMethod"));
    SuppressMethod tested = spy(new SuppressMethod());
    assertEquals(20, tested.myMethod());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) SuppressMethodParent(samples.suppressmethod.SuppressMethodParent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with SuppressMethod

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

the class MemberModificationExampleTest method suppressAllMethodsExample.

@Test
public void suppressAllMethodsExample() throws Exception {
    suppress(methodsDeclaredIn(SuppressMethod.class));
    final SuppressMethod tested = new SuppressMethod();
    assertNull(tested.getObject());
    assertNull(SuppressMethod.getObjectStatic());
    assertEquals(0, tested.getByte());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with SuppressMethod

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

the class StubMethodTest method whenStubbingInstanceMethodWithPrimiteValueTheMethodReturnsTheStubbedValue.

@Test
public void whenStubbingInstanceMethodWithPrimiteValueTheMethodReturnsTheStubbedValue() throws Exception {
    float expectedValue = 4;
    stub(method(SuppressMethod.class, "getFloat")).toReturn(expectedValue);
    SuppressMethod tested = new SuppressMethod();
    assertEquals(expectedValue, tested.getFloat(), 0.0f);
    assertEquals(expectedValue, tested.getFloat(), 0.0f);
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with SuppressMethod

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

the class StubMethodTest method whenStubbingInstanceMethodTheMethodReturnsTheStubbedValue.

@Test
public void whenStubbingInstanceMethodTheMethodReturnsTheStubbedValue() throws Exception {
    String expectedValue = "Hello";
    stub(method(SuppressMethod.class, "getObject")).toReturn(expectedValue);
    SuppressMethod tested = new SuppressMethod();
    assertEquals(expectedValue, tested.getObject());
    assertEquals(expectedValue, tested.getObject());
}
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