Search in sources :

Example 31 with SuppressMethod

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

the class SuppressMethodTest method suppressAllMethodsInMultipleClasses.

@Test
public void suppressAllMethodsInMultipleClasses() throws Exception {
    suppress(methodsDeclaredIn(SuppressMethod.class, SuppressMethodExample.class));
    SuppressMethod tested1 = new SuppressMethod();
    SuppressMethodExample tested2 = new SuppressMethodExample();
    // Should not cause an NPE when suppressing code.
    tested1.invokeVoid(null);
    assertNull(tested1.getObject());
    assertEquals(0, tested1.getInt());
    assertNull(tested2.getObject());
}
Also used : SuppressMethodExample(samples.suppressmethod.SuppressMethodExample) SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with SuppressMethod

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

the class SuppressMethodTest method testSuppressMethodInParentOnly.

@Test
public void testSuppressMethodInParentOnly() throws Exception {
    suppress(method(SuppressMethodParent.class, "myMethod"));
    SuppressMethod tested = 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 33 with SuppressMethod

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

the class SuppressMethodTest method testInvokeVoid_noParameterTypeSupplied.

@Test
public void testInvokeVoid_noParameterTypeSupplied() throws Exception {
    suppress(method(SuppressMethod.class, "invokeVoid"));
    SuppressMethod tested = new SuppressMethod();
    // Should not cause an NPE when suppressing code.
    tested.invokeVoid(null);
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with SuppressMethod

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

the class SuppressMethodTest method testGetDouble.

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

Example 35 with SuppressMethod

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

the class SuppressMethodTest method testGetFloat.

@Test
public void testGetFloat() throws Exception {
    suppress(method(SuppressMethod.class, "getFloat"));
    SuppressMethod tested = new SuppressMethod();
    assertEquals("A method returning a float should return 0.0f after suppressing method code.", 0.0f, tested.getFloat(), 0);
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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