Search in sources :

Example 6 with SuppressMethod

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

the class SuppressMethodTest method testInvokeVoid.

@Test
public void testInvokeVoid() throws Exception {
    suppress(method(SuppressMethod.class, "invokeVoid", new Class<?>[] { StringBuilder.class }));
    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 7 with SuppressMethod

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

the class ProxyMethodTest method mockingAndMethodProxyAtTheSameTimeWorks.

@Test
public void mockingAndMethodProxyAtTheSameTimeWorks() throws Exception {
    replace(method(SuppressMethod.class, "getObjectStatic")).with(new DelegatingInvocationHandler());
    SuppressMethod tested = mock(SuppressMethod.class);
    when(tested.getObject()).thenReturn("Hello world");
    assertSame(SuppressMethod.OBJECT, SuppressMethod.getObjectStatic());
    assertEquals("Hello world", tested.getObject());
    verify(tested).getObject();
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with SuppressMethod

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

the class ProxyMethodTest method replaceInstanceMethodsWork.

@Test
@Ignore("Doesn't work atm")
public void replaceInstanceMethodsWork() throws Exception {
    replace(method(SuppressMethod.class, "getObject")).with(method(SuppressMethodExample.class, "getStringObject"));
    SuppressMethod tested = new SuppressMethod();
    assertEquals("test", tested.getObject());
}
Also used : SuppressMethodExample(samples.suppressmethod.SuppressMethodExample) SuppressMethod(samples.suppressmethod.SuppressMethod) Ignore(org.junit.Ignore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with SuppressMethod

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

the class ProxyMethodTest method expectionThrowingMethodProxyWorksForMethodNames.

@Test(expected = ArrayStoreException.class)
public void expectionThrowingMethodProxyWorksForMethodNames() throws Exception {
    replace(method(SuppressMethod.class, "getObject")).with(new ThrowingInvocationHandler());
    new SuppressMethod().getObject();
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with SuppressMethod

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

the class ProxyMethodTest method expectionThrowingMethodProxyWorksForJavaLangReflectMethods.

@Test(expected = ArrayStoreException.class)
public void expectionThrowingMethodProxyWorksForJavaLangReflectMethods() throws Exception {
    replace(method(SuppressMethod.class, "getObject")).with(new ThrowingInvocationHandler());
    new SuppressMethod().getObject();
}
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