Search in sources :

Example 1 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 2 with SuppressMethod

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

the class StubMethodTest method whenStubbingInstanceMethodByPassingTheMethodTheMethodReturnsTheStubbedValue.

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

Example 3 with SuppressMethod

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

the class SuppressMethodTest method testGetBoolean.

@Test
public void testGetBoolean() throws Exception {
    suppress(method(SuppressMethod.class, "getBoolean"));
    SuppressMethod tested = new SuppressMethod();
    assertFalse("A method returning a boolean should return false after suppressing method code.", tested.getBoolean());
}
Also used : SuppressMethod(samples.suppressmethod.SuppressMethod) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with SuppressMethod

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

the class SuppressMethodTest method testGetByte.

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

Example 5 with SuppressMethod

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

the class SuppressMethodTest method testGetInt.

@Test
public void testGetInt() throws Exception {
    suppress(method(SuppressMethod.class, "getInt"));
    SuppressMethod tested = new SuppressMethod();
    assertEquals("A method returning an int should return 0 after suppressing method code.", 0, tested.getInt());
}
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