Search in sources :

Example 26 with SuppressMethod

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

the class StubMethodTest method whenStubbingInstanceMethodToThrowExceptionTheMethodThrowsTheStubbedException.

@Test
public void whenStubbingInstanceMethodToThrowExceptionTheMethodThrowsTheStubbedException() throws Exception {
    Exception expected = new Exception("message");
    stub(method(SuppressMethod.class, "getObject")).toThrow(expected);
    SuppressMethod tested = new SuppressMethod();
    try {
        tested.getObject();
        fail();
    } catch (Exception e) {
        assertEquals("message", e.getMessage());
    }
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) MethodNotFoundException(org.powermock.reflect.exceptions.MethodNotFoundException) TooManyMethodsFoundException(org.powermock.reflect.exceptions.TooManyMethodsFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 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)

Example 28 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 29 with SuppressMethod

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

the class StubMethodTest method whenStubbingInstanceMethodWithWrongReturnTypeThenClasscastExceptionIsThrown.

@Test(expected = ClassCastException.class)
public void whenStubbingInstanceMethodWithWrongReturnTypeThenClasscastExceptionIsThrown() throws Exception {
    String illegalReturnType = "Hello";
    stub(method(SuppressMethod.class, "getFloat")).toReturn(illegalReturnType);
    SuppressMethod tested = new SuppressMethod();
    tested.getFloat();
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with SuppressMethod

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

the class SuppressMethodTest method suppressOverridingMethod.

@Test
public void suppressOverridingMethod() throws Exception {
    suppress(method(SuppressMethod.class, "myMethod"));
    SuppressMethod tested = new SuppressMethod();
    assertEquals(0, tested.myMethod());
}
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